在Android SDK SDK 4.1+中调用Android refreshCurrentAccessTokenAsync
在Android中,我调用refreshCurrentAccessTokenAsync()
但似乎没有callback。 我在注册callbackManager之前调用refreshCurrentAccessTokenAsync()
,它永远不会被调用, onActivityResult
也不会。
Doc也没有说任何: https : //developers.facebook.com/docs/reference/android/current/class/AccessToken/
在iOS中,有一个完成处理程序。
+ (void)refreshCurrentAccessToken:(FBSDKGraphRequestHandler)completionHandler;
在用户撤销其令牌或移除权限的情况下,最佳做法是什么?
我假设在IOS上我会检查GraphRequest
完成处理程序,但没有看到什么是没有callback的Android推荐的方式。
谢谢!
如果用户已经吊销了令牌,则无法刷新令牌。 如果当前的访问令牌仍然有效,则只能刷新它。
该方法也直接调用Graph API,这就是为什么没有onActivityResult被调用。
如果刷新成功,则访问令牌将被更新,您可以使用AccessTokenTracker来获取通知。
最后,你为什么直接调用这个方法? 通常只要使用graphicsAPI,SDK就会自动刷新令牌。
不幸的是,这是由于FaceBook的SDK文档不佳。
您必须为AccessToken
设置一个跟踪器,类似于您使用Profile
。
我的代码如下:
private AccessTokenTracker mAccessTokenTracker; private void loginToMyFbApp() { FacebookSdk.sdkInitialize(this); if (AccessToken.getCurrentAccessToken() != null) { mAccessTokenTracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) { mAccessTokenTracker.stopTracking(); if(currentAccessToken == null) { //(the user has revoked your permissions - //by going to his settings and deleted your app) //do the simple login to FaceBook } else { //you've got the new access token now. //AccessToken.getToken() could be same for both //parameters but you should only use "currentAccessToken" } } }; AccessToken.refreshCurrentAccessTokenAsync(); } else { //do the simple login to FaceBook } }
编辑
Astrount在下面的评论中正确地指出了删除了startTracking()
调用。