gpt4 book ai didi

java - Android Facebook 登录 API 仅返回名称和 ID

转载 作者:搜寻专家 更新时间:2023-11-01 08:22:45 24 4
gpt4 key购买 nike

您好,我在 android 应用程序中使用 Facebook graph Api,我能够提交请求并获得响应,但尽管我的范围是 "email", "user_birthday", "public_profile" 它只返回名称和 ID。

private void onFblogin()  {
callbackmanager = CallbackManager.Factory.create();

// Set permissions
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList( "email", "user_birthday", "public_profile"));

LoginManager.getInstance().registerCallback(callbackmanager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {

System.out.println("Success");
GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject json, GraphResponse response) {
if (response.getError() != null) {
// handle error
System.out.println("ERROR");
} else {
System.out.println("Success");
try {

String jsonresult = String.valueOf(json);
System.out.println("JSON Result"+jsonresult);

String name = json.getString("name");
String str_email = json.getString("email");
String str_id = json.getString("id");


//boolean loggedIn = AccessToken.getCurrentAccessToken() == null;
//get profile data
// LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile"));
String str_firstname = json.getString("first_name");
String str_lastname = json.getString("last_name");

} catch (JSONException e) {
e.printStackTrace();
}
}
}

}).executeAsync();

}

@Override
public void onCancel() {
Log.d("facebook Login","On cancel");
}

@Override
public void onError(FacebookException error) {
Log.d("facebook Login",error.toString());
}
});
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
} else if(requestCode == FB_SIGN_IN){
callbackmanager.onActivityResult(requestCode, resultCode, data);
}
}

渐变

implementation 'com.facebook.android:facebook-login:[4,5)'

enter image description here

谁能帮我获取public_profile中的所有信息

最佳答案

您没有指定任何字段,请查看文档:https://developers.facebook.com/docs/android/graph

例如:

GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,birthday");
request.setParameters(parameters);
request.executeAsync();

如果不指定 fields 参数,您只会在响应中获得一些默认字段。这适用于所有 API 调用。

查看文档中的“选择字段”:https://developers.facebook.com/docs/graph-api/using-graph-api

关于java - Android Facebook 登录 API 仅返回名称和 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48810998/

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