[英]Android Facebook Login API returns only name and id
嗨,我在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)'
有人可以帮我获取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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.