我想获取Facebook中记录的用户信息。当我在LoginManager.getInstance()之后调用GraphRequest.newMeRequest时.logInWithReadPermissions一切正常,我得到用户信息,包括姓名和电子邮件等。但如果我在下次启动app时调用newMeRequest(不调用loginwithreadpermissions),则会出现错误:
{Request: accessToken: {AccessToken token:ACCESS_TOKEN_REMOVED permissions:[user_friends, email, public_profile, user_birthday]}, graphPath: me, graphObject: null, httpMethod: GET, parameters: Bundle[{}]}
[{Response: responseCode: 200, graphObject: {"id":"799921370127965","gdpv4_nux_enabled":false,"supports_implicit_sdk_logging":true,"android_sdk_error_categories":[{"recovery_message":"Please log in to this app again to reconnect your Facebook account.","items":[{"code":102},{"code":190}],"name":"login_recoverable"}],"android_dialog_configs":{"data":[{"versions":["20140701"],"url":"\/connect\/dialog\/MPlatformLikeJSDialog","name":"com.facebook.platform.action.request.LIKE_DIALOG|LIKE_DIALOG"},
{"versions":["20140701"],"url":"\/connect\/dialog\/MPlatformAppInvitesJSDialog","name":"com.facebook.platform.action.request.APPINVITES_DIALOG|APP_INVITES_DIALOG"}]},"gdpv4_nux_content":"New! You're in control – choose what info you want to share with apps."}, error: null}]
以下是我的代码
public void facebookLogin()
{
if (!isFBLogin)
LoginManager.getInstance().logInWithReadPermissions(this,Arrays.asList("public_profile","email", "user_birthday", "user_friends"));
else
loadFBInfo();
}
public void loadFBInfo()
{
GraphRequest request = GraphRequest.newMeRequest(
accessTokenApp,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,GraphResponse response) {
Log.d(APPACTTAG, "newMeDone..");
}
});
request.executeAsync();
}
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(APPACTTAG, "FB Login Result .... " + loginResult.hashCode());
loadFBInfo();
}
@Override
public void onCancel() {
// App code
Log.d(APPACTTAG, "FB Login Cancel Result ...");
}
@Override
public void onError(FacebookException exception) {
// App code
Log.d(APPACTTAG, "FB onError ..." + exception.toString());
});