Sat*_*man 3 java android facebook facebook-graph-api facebook-android-sdk
您好,我在 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);
}
}
Run Code Online (Sandbox Code Playgroud)
摇篮
implementation 'com.facebook.android:facebook-login:[4,5)'
Run Code Online (Sandbox Code Playgroud)
有人可以帮我获取 public_profile 中的所有信息吗
您没有指定任何字段,请查看文档:https://developers.facebook.com/docs/android/graph
\n\n例如:
\n\nGraphRequest request = GraphRequest.newMeRequest(\n accessToken,\n new GraphRequest.GraphJSONObjectCallback() {\n @Override\n public void onCompleted(\n JSONObject object,\n GraphResponse response) {\n // Application code\n }\n });\nBundle parameters = new Bundle();\nparameters.putString("fields", "id,name,email,birthday");\nrequest.setParameters(parameters);\nrequest.executeAsync();\nRun Code Online (Sandbox Code Playgroud)\n\n如果不指定 fields 参数,您将只能在响应中获得一些默认字段。所有 API 调用的\xc2\xb4s。
\n\n查看文档中的“选择字段”:https://developers.facebook.com/docs/graph-api/using-graph-api
\n| 归档时间: |
|
| 查看次数: |
1401 次 |
| 最近记录: |