错误验证访问令牌:用户未授权的应用程序。 Facebook的SDK 4 [英] Error validating access token: The user has not authorized application. Facebook SDK 4
问题描述
下面是这样的:
如果我previously通过
授予读取权限我的应用程序 LoginManager.getInstance()logInWithReadPermissions(这一点,Arrays.asList(电子邮件));
然后,当我需要分享我要求通过发布权限:
LoginManager.getInstance()logInWithPublishPermissions(getActivity(),Arrays.asList(publish_actions))。
一切工作正常,直到我删除权限我的Web应用程序。
如果应用程序被打死或停止,我需要分享,我会检查,如果我仍然有权限:
如果(userAuthorizedMyApp()){
LoginManager.getInstance()logInWithPublishPermissions(此,Arrays.asList(publish_actions))。
}其他{
。LoginManager.getInstance()logInWithReadPermissions(这一点,Arrays.asList(电子邮件));
}
方法userAuthorizedMyApp()返回false(空的accessToken):
私人布尔userAuthorizedMyApp(){
布尔授权;
的accessToken的accessToken = AccessToken.getCurrentAccessToken();
如果(调试)Log.v(TAG的accessToken [+的accessToken +]); 如果(的accessToken!= NULL){
SET<串GT; currentPermissions = accessToken.getPermissions();
授权= currentPermissions.contains(public_profile);
}其他{
授权= FALSE;
}
如果(调试)Log.v(TAGuserAuthorizedMyApp [+授权+]); 返回的授权;
}
和我尝试做平常登录,就好像它是第一次:
LoginManager.getInstance()logInWithReadPermissions(这一点,Arrays.asList(电子邮件));
和我收到的:
公共无效onerror的(FacebookException错误)
onError的,错误{的HTTPStatus:-1,错误code:190,错误类型:空,的errorMessage:错误验证访问令牌:用户没有授权的应用程序123456789123456}
块引用>任何想法我做错了吗?
解决方案就这样做:
@覆盖
公共无效onerror的(FacebookException错误){
Timber.e(错误,错误的Facebook登录时);
AccessToken.setCurrentAccessToken(NULL);
LoginManager.getInstance()。logInWithReadPermissions(这一点,Arrays.asList(电子邮件))
}Here is the case :
If I previously granted read permissions to my application via
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
Then, when I need to share I request publish permissions via :
LoginManager.getInstance().logInWithPublishPermissions(getActivity(), Arrays.asList("publish_actions"));
Everything works fine until I removed permissions for my application in Web.
If Application was killed or stopped and I need to share I will check if I still have the permissions:
if(userAuthorizedMyApp()){ LoginManager.getInstance().logInWithPublishPermissions(this, Arrays.asList("publish_actions")); } else { LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email")); }
Method userAuthorizedMyApp() returns 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; }
And I try to do usual login, as if it were first time :
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
And I receive :
public void onError(FacebookException error)
onError, error {HttpStatus: -1, errorCode: 190, errorType: null, errorMessage: Error validating access token: The user has not authorized application 123456789123456.}
Any ideas what I am doing wrong ?
解决方案Just do something like:
@Override public void onError(FacebookException error) { Timber.e(error, "Error during facebook login"); AccessToken.setCurrentAccessToken(null); LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email")) }
这篇关于错误验证访问令牌:用户未授权的应用程序。 Facebook的SDK 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!