当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Facebook Android SDK 4.1+

问题描述:

I'm upgrading to the latest Android and iOS sdks for Facebook and had two question.

Now that we have a concept of an access token that has to be refreshed periodically, I have been reading about the iOS SDK and noticed the below in the SDK:

/*!

@abstract Refresh the current access token's permission state and extend the token's expiration date,

if possible.

@param completionHandler an optional callback handler that can surface any errors related to permission refreshing.

@discussion On a successful refresh, the currentAccessToken will be updated so you typically only need to

observe the `FBSDKAccessTokenDidChangeNotification` notification.

If a token is already expired, it cannot be refreshed.

*/

+ (void)refreshCurrentAccessToken:(FBSDKGraphRequestHandler)completionHandler;

This method is for refreshing the SDK and is in the class FBSDKAccessToken. On the Android side I'm trying to find out if the same is true and read the code as well as documentation on this, it doesn't say if the AccessToken class's refresh method (refreshCurrentAccessTokenAsync) has to be called before expiration.

I have read this in the documentation:

https://developers.facebook.com/docs/reference/android/current/class/AccessToken/

Even for getLastRefresh() it says the below:

Gets the date at which the token was last refreshed. Since tokens expire, the Facebook SDK will attempt to renew them periodically.

This is unlike iOS where refreshing doesn't happen automatically. Is my assumption correct? That the iOS and Android sdks are handling refreshing differently?

Also, what is the best practice for refreshing tokens? I have been refreshing tokens in didFinishLaunchingWithOptions in iOS and on Android I do it when the application loads. However, it would help if there was more information on the best strategy with the SDKs.

I have been reading the following on this:

https://www.sammyk.me/access-token-handling-best-practices-in-facebook-php-sdk-v4

https://www.quora.com/With-the-Facebook-Graph-API-is-there-a-way-to-get-a-new-access-token-without-needing-to-re-enter-the-users-password

网友答案:

The access token will get refreshed automatically in the Android SDK if you make a graph request (it gets piggy-backed onto the request that you make).

分享给朋友:
您可能感兴趣的文章:
随机阅读: