gpt4 book ai didi

Android Facebook GraphRequest 不返回电子邮件

转载 作者:行者123 更新时间:2023-11-29 15:04:50 25 4
gpt4 key购买 nike

我看了几个关于这个问题的帖子,但没有找到解决方案。

     facebookLoginButton = (LoginButton) findViewById(R.id.facebook_login_button);
facebookLoginButton.setReadPermissions(Arrays.asList("read_stream", "user_photos", "email", "user_location"));

// create callback manager for facebook
callbackManager = CallbackManager.Factory.create();

facebookLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "LOGGED IN");

GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.d(TAG, "Facebook graph response: " + response.toString());
try {
// get only the part before the @ symbol
String email_username = object.getString("email").substring(0, object.getString("email").indexOf("@"));
editor = preferences.edit();
editor.putString("username", email_username);
editor.commit();

Log.d(TAG, "logging in user " + preferences.getString("username", "") + " with userID: " + preferences.getString("userID", ""));
SpinLoginTask spinLoginTask = new SpinLoginTask(LoginActivity.this);
spinLoginTask.execute("facebook");
} catch (Exception e) {
e.printStackTrace();
}

}
});
request.executeAsync();
}

我收到以下回复:

Facebook graph response: {Response:  responseCode: 200, graphObject: {"name":"Spin Tester","id":"xxxxx"}, error: null}
org.json.JSONException: No value for email

既然我在按钮上设置了读取权限以提供所有信息,为什么它没有出现在图形请求响应中?

最佳答案

试试我一直使用的这段代码:EDIT

实际上,您需要更改一小部分代码:

    GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.d(TAG, "Facebook graph response: " + response.toString());
try {
// get only the part before the @ symbol
String email_username = object.getString("email").substring(0, object.getString("email").indexOf("@"));
editor = preferences.edit();
editor.putString("username", email_username);
editor.commit();

Log.d(TAG, "logging in user " + preferences.getString("username", "") + " with userID: " + preferences.getString("userID", ""));
SpinLoginTask spinLoginTask = new SpinLoginTask(LoginActivity.this);
spinLoginTask.execute("facebook");
} catch (Exception e) {
e.printStackTrace();
}

}
});

//ADD THIS LINES PLEASE
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}

关于Android Facebook GraphRequest 不返回电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38535143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com