0
我正在使用Facebook registerCallBack方法獲取當前用戶信息。我遇到的問題是在嘗試檢索電子郵件地址時。Facebook Android登錄獲取用戶電子郵件地址
// Callback registration
FBLogin.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
final Profile profile = Profile.getCurrentProfile();
if (profile != null) {
}
//Toast.makeText(FacebookLogin.this,"Wait...",Toast.LENGTH_SHORT).show();
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
String email_id = object.getString("email");
String gender = object.getString("gender");
String facebook_id=profile.getId();
String f_name=profile.getFirstName();
String m_name=profile.getMiddleName();
String l_name=profile.getLastName();
String full_name=profile.getName();
String profile_image=profile.getProfilePictureUri(400, 400).toString();
Log.i("facebook_id",facebook_id);
Log.i("f_name",f_name);
Log.i("m_name",m_name);
Log.i("l_name",l_name);
Log.i("full_name",full_name);
Log.i("profile_image",profile_image);
Log.i("gender",gender);
Log.i("email_id",email_id+"");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday, friends,albums");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
使用此代碼我碰到下面的日誌:
org.json.JSONException: No value for email
我已經確定該電子郵件是公開的,這是一個問題,因爲我曾與谷歌加登錄類似的問題的情況下腳本。
您需要詢問電子郵件字段 – WizKid
@wizkid我在參數中指定電子郵件地址是 – jampez77
哦,您是否要求用戶提供電子郵件許可? – WizKid