android – 验证访问令牌时出错:用户未授权应用程序. Facebook SDK 4
作者:互联网
情况如下:
如果我以前通过我的应用程序授予读取权限
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
然后,当我需要共享时,我通过以下方式请求发布权限:
LoginManager.getInstance().logInWithPublishPermissions(getActivity(), Arrays.asList("publish_actions"));
在我删除Web应用程序的权限之前,一切正常.
如果应用程序被杀死或停止并且我需要共享,我将检查是否仍然拥有权限:
if(userAuthorizedMyApp()){
LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
} else {
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
}
方法userAuthorizedMyApp()返回false(accessToken null):
private boolean userAuthorizedMyApp() {
boolean authorized;
AccessToken accessToken = AccessToken.getCurrentAccessToken();
if(DEBUG) Log.v(TAG, "accessToken [" + accessToken +"]");
if(accessToken != null){
Set<String> currentPermissions = accessToken.getPermissions();
authorized = currentPermissions.contains("public_profile");
} else {
authorized = false;
}
if(DEBUG) Log.v(TAG, "userAuthorizedMyApp[" + authorized +"]");
return authorized;
}
我尝试通常登录,就好像它是第一次:
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
我收到:
public void one rror(FacebookException error)
onError, error {HttpStatus: -1, errorCode: 190, errorType: null, errorMessage: Error validating access token: The user has not authorized application 123456789123456.}
我有什么想法我做错了吗?
解决方法:
做一些像:
@Override
public void one rror(FacebookException error) {
Timber.e(error, "Error during facebook login");
AccessToken.setCurrentAccessToken(null);
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"))
}
标签:android,facebook,facebook-sdk-4-0,facebook-permissions 来源: https://codeday.me/bug/20190528/1170781.html