我想從Facebook登錄名獲取姓名和電子郵件。無法從Facebook獲取姓名和電子郵件
我使用:compile 'com.facebook.android:facebook-android-sdk:4.+'
我能進onSuccess
但代碼不進入GraphRequest,我想這就是爲什麼我不能得到的姓名和電子郵件(我也想獲得簡介圖片)
我得到的自動生成的代碼(GraphRequest)從Facebook開發瀏覽器阿比圖
public class LoginActivity
{
LoginButton buttonLoginFacebook;
@Nullable
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
buttonLoginFacebook = (LoginButton) findViewById(R.id.connectWithFbButton);
buttonLoginFacebook.setReadPermissions(Arrays.asList(
"public_profile", "email"));
FacebookSdk.setIsDebugEnabled(true);
FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
FacebookSdk.addLoggingBehavior(LoggingBehavior.REQUESTS);
buttonLoginFacebook.setOnClickListener(this);
buttonLoginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
//----->THE CODE JUMPS FROM HERE
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
mensajeFACEBOOK="TRYING TO GET NAME";
}
});
//----->TO HERE
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,first_name,last_name");
request.setParameters(parameters);
request.executeAsync();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
});
}
}
我應該在哪裏粘貼方法registerCallBackMethod()?在OnCreate裏面? – Pierre
和sendValues呢?你在哪裏宣佈它? – Pierre
是的,在onCreate和sendValues只是一些API調用。別擔心。 –