[英]Get Facebook user Id by login Facebook account with android
我想通過登錄Facebook帳戶在Android中獲取Facebook用戶ID。 我無法以正確的方式獲得ID。 請指導我,我如何獲得它。 我的代碼是。
public void onSuccess(LoginResult loginResult) {
// App code
GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
if (response.getError() != null) {
// handle error
} else {
String name= object.optString("name");
String id = object.optString("id");
Intent i = new Intent(Login.this, MainActivity.class);
startActivity(i);
}
}
}).executeAsync();
}
您的代碼看起來不錯,這是我目前正在使用的代碼,也許有幫助。
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
GraphRequest request = GraphRequest.newMeRequest(
AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
String email=object.optString("email");
String id=object.optString("id")
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "email");
request.setParameters(parameters);
request.executeAsync();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.