【发布时间】:2016-05-31 20:32:57
【问题描述】:
我尝试使用AccessToken 获取用户email,这是我从Facebook SDK 获得的
-
如果我使用
Graph API Explorer的AccessToken,我可以得到id、name和email,不管我使用浏览器还是OkHttp:"https://graph.facebook.com/" + user_id + "?fields=email,name&access_token=" + access_token_from_graph_explorer
我得到这样的回应:
{
"email": "mail@com",
"name": "John Doe",
"id": "4545"
}
如果我使用AccessToken.getCurrentAccessToken().getToken() 方法获取的token,我不会在JSONObject 中得到email。
- 使用
Graph Explorer我可以看到我的id。我试着用这种方式提出请求:
"https://graph.facebook.com/me?fields=email,name&access_token="
还有这个:
"https://graph.facebook.com/" + id + "?fields=email,name&access_token="
在第二个变体中,我使用了"Unsupported get request. Object with ID 'xxxxxxxxxxx' does not exist, cannot be loaded due to missing permissions...,同时使用了我的id。当我尝试使用另一个user 的id 时,我仍然没有得到email。
Bundle bundle = new Bundle();
bundle.putString("fields", "email,name");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"me",
bundle,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
System.out.println("data = " + response.toString());
}
}
).executeAsync();
有了这个变种,我也没有达到email。
我很困惑。告诉我,我怎样才能找回用户的电子邮件。
3.登录后我尝试:
public void onSuccess(LoginResult loginResult) {
System.out.println("succses =" + loginResult.getAccessToken().getToken());
accessToken = loginResult.getAccessToken();
GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse graphResponse) {
Log.d("TAG", user.optString("email"));
Log.d("TAG", user.optString("name"));
Log.d("TAG", user.optString("id"));
init();
}
}).executeAsync();
}
但我没有看到TAG 的电子邮件
附言graph explorer 中的所有权限均已开启。
【问题讨论】:
-
在stackoverflow上试试这个答案...我遇到了同样的问题...stackoverflow.com/a/33412596
-
@ExceptionLover 是的,谢谢。这有帮助。
-
请接受我的回答...!!