gpt4 book ai didi

android - 在 Facebook Android API 中访问用户生日时出现不存在的字段错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:48:29 25 4
gpt4 key购买 nike

我想访问用户的生日和性别,但是当我尝试访问生日时出现错误。我使用的是 Facebook SDK 版本 facebook-android-sdk:4.18.0。

它给我这个错误:

{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 100, errorType: OAuthException, errorMessage: (#100) Tried accessing nonexisting field (user_birthday) on node type (User)}}

这是我的代码:

public class MainActivity extends AppCompatActivity {
private CallbackManager callbackManager;
private TextView info;
private LoginButton loginButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();

setContentView(R.layout.activity_main);
info = (TextView)findViewById(R.id.info);
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.v("LoginActivity", response.toString());

// Application code
String email = object.optString("email");
String birthday = object.optString("birthday");
String name = object.optString("name"); // 01/31/1980 format
info.setText("email: " +
email + "\n" +
"birthday " + birthday+
"\n name"+name);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,user_birthday");
request.setParameters(parameters);
request.executeAsync();

}

@Override
public void onCancel() {
info.setText("Login attempt cancelled.");
}

@Override
public void onError(FacebookException e) {
info.setText("Login attempt failed.");
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}

最佳答案

在参数中你应该使用生日而不是用户生日:

parameters.putString("fields", "id, name, email, gender, birthday");

有关用户简介的可用字段,请参阅文档: https://developers.facebook.com/docs/graph-api/reference/user/

关于android - 在 Facebook Android API 中访问用户生日时出现不存在的字段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41364085/

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