尝试Facebook登录过程但获得有关OAuthException的例外

时间:2015-12-10 08:12:16

标签: android facebook facebook-login

我正在使用facebook android sdk v4.7.0 尝试登录Facebook并获得例外:

{Response:responseCode:400,graphObject:null,error:{HttpStatus:400,errorCode:2500,errorType:OAuthException,errorMessage:语法错误"预期名称。"在字符33:id,first_name,last_name,email,}}

以下代码:

fbLoginButton.setReadPermissions(Arrays.asList("public_profile", "email"));
fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Bundle parameters = new Bundle();
parameters.putString("fields", "id, first_name, last_name, email,");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"me",
parameters,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i("LoginActivity", response.toString());
prepareFacebookData(response.getJSONObject());
}
}
).executeAsync();
}
@Override
public void onCancel() {
printToastMessage("Canceled");
}
@Override
public void onError(FacebookException error) {
printToastMessage(error.getCause().toString());
}
});

1 个答案:

答案 0 :(得分:1)

这里有一个额外的逗号

parameters.putString("fields", "id, first_name, last_name, email,");

这会让facebook期待另一个字段,但不会因此你会告诉你的请求是无效的,因为你传递了额外的空字符串。

所以解决方法是将其删除到

parameters.putString("fields", "id, first_name, last_name, email");