如何使用在新的Facebook SDK中的方法“openWithImportedAccessToken”为Android 3.02 [英] How do you use the method 'openWithImportedAccessToken' in the new Facebook SDK for Android 3.02

查看:230
本文介绍了如何使用在新的Facebook SDK中的方法“openWithImportedAccessToken”为Android 3.02的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的Facebook SDK为Android(3.0)有去precated很多老办法,包括setAccessToken方法。造成这种情况的置换(我认为)是方法openWithImportedAccessToken

The new Facebook SDK for Android (3.0) has deprecated a lot of the old methods, including the setAccessToken method. The replacement for this (I think) is the method openWithImportedAccessToken

<一个href=\"https://developers.facebook.com/docs/reference/android/3.0/Session#openWithImportedAccessToken%28String,%20Date,%20Date,%20AccessTokenSource,%20List,%20StatusCallback%29\" rel=\"nofollow\">https://developers.facebook.com/docs/reference/android/3.0/Session#openWithImportedAccessToken(String,日期,日期,AccessTokenSource,列表,StatusCallback)。

人是否有使用这个任何的例子吗?尤其是你如何获得访问令牌的到期时间和上次刷新时间?

Does anyone have any examples of using this? In particular how do you get the expiration time and last refresh time of the access token?

推荐答案

如果您有特定参数的数据,也有合理的默认值,你可以在这里填写导致次优,但并非太糟糕行为。

If you have no data for a particular parameter, there are reasonable defaults you can fill in here that result in sub-optimal-but-not-too-bad behavior.

请记住,你只能调用这个API在第一时间在升级到3.x的Andr​​oid SDK中导入在任何地方你之前将其存储令牌后运行。此后,管理SDK默认情况下,令牌缓存。因此,任何次优的行为应该是一次性的本地化此升级。

Keep in mind that you should only be calling this API the first time you run after upgrading to the 3.x Android SDK to import the token from wherever you were storing it before. Afterwards, the SDK manages the token cache by default. So any sub-optimal behavior should be one-time localized to this upgrade.

提供你所知道的数据。因为你不知道是什么,它​​主要是没关系指定:

Provide what data you know. For what you don't know, it is mostly okay to specify that:


  • 的截止日期为60天,从现在

  • 最后更新时间是现在

  • 的AccessTokenSource是FACEBOOK_APPLICATION

  • 权限列表为空

请注意,如果你总是要求相同的权限,因此知道哪些权限旧的令牌,使用这些。

Note that if you always ask for the same permissions and therefore know what permissions your old token has, use those.

这是更好,如果你能为这些参数提供正确的值,但缺点一般并不可怕。这里有缺点躺在这个API:

It is better if you can provide the correct values for these parameters, but the downsides are generally not terrible. Here are the downsides to lying to this API:


  • 下行的指定到期时间晚于它:如果令牌已过期,你会做一个请求,不管怎样,有Facebook的服务返回了一个错误,而不是就立即注意到它客户端。

  • 下行指定的最后更新时间更近的比它的:SDK将尝试刷新第一个请求令牌,而不是等待24小时

  • 指定AccessTokenSource作为FACEBOOK_APPLICATION的下行:如果令牌从传来的WebView,SDK将尝试刷新你的令牌,该操作将失败。最终令牌将到期,随后登录将纠正AccessTokenSource值。

  • 下行的指定空权限:当你将要执行的操作,您应检查是否有权限做了手术,如果不是你应该叫Session.reauthorize()请求权限。如果调用openWithImportedAccessToken()与空列表(或更少的权限你确实有),然后你会觉得你没有许可,并会再次询问用户的权限。只要这是在用户的上下文中操作的方式,其中该权限预期的操作,这不应该太不和谐给用户。

  • Downside of specifying that the expiration time is later than it is: if the token is expired, you may make a request anyway and have the Facebook service return an error rather than noticing it immediately on the client side.
  • Downside of specifying that the last updated time is more recent than it was: the SDK will try to refresh the token on the first request rather than waiting for 24 hours.
  • Downside of specifying AccessTokenSource as FACEBOOK_APPLICATION: if the token came from a WebView, the SDK will try to refresh your token, and the operation will fail. Eventually the token will expire, and the subsequent login will correct the AccessTokenSource value.
  • Downside of specifying empty permissions: when you are about to perform an operation, you should check if you have permissions to do the operation, and if not you should call Session.reauthorize() to request permissions. If you call openWithImportedAccessToken() with an empty list (or fewer permissions that you actually have), then you will think you do not have the permission and will ask the user again for the permission. As long as this is in the context of the user doing an operation where this permission is expected, this should not be too jarring to the user.

这篇关于如何使用在新的Facebook SDK中的方法“openWithImportedAccessToken”为Android 3.02的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆