我在fb登录时使用它:
LoginManager.getInstance().logInWithReadPermissions(FindFriendActivity.this, Arrays.asList("public_profile", "user_friends", "email"));
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>()
{
@Override
public void onSuccess(LoginResult loginResult)
{
Log.d("Success", "Login");
GraphRequest graphRequestAsyncTask = new GraphRequest(
loginResult.getAccessToken(), "/me/friends", null, HttpMethod.GET, new GraphRequest.Callback()
{
public void onCompleted(GraphResponse response)
{
JSONArray rawName = response.getJSONObject().getJSONArray("data");
}
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,picture,email");
graphRequestAsyncTask.setParameters(parameters);
graphRequestAsyncTask.executeAsync();
}
@Override
public void onCancel()
{
Utilities.ShowToast(mContext, "Facebook Login cancel");
}
@Override
public void onError(FacebookException exception)
{
Utilities.ShowToast(mContext, exception.getMessage());
}
}
);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
清单:
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<uses-permission android:name="android.permission.INTERNET"/>
回应:
{Response: responseCode: 200, graphObject: {"data":[{"id":"10210065337685894","name":"abc","picture":{"data":{"is_silhouette":false,"url":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xlp1\/v\/t1.0-1\/p50x50\/13501928_10209152837153951_2277267834804945940_n.jpg?oh=1fdb4269d216309e39afe4fc9460011f&oe"}}},{"id":"1249098285123628","name":"xyz","picture":{"data":{"is_silhouette":false,"url":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xfp1\/v\/t1.0-1\/p50x50\/13501829_1199623916737732_4120441565269954276_n.jpg?oh=d030d56a261964d37ffe287887122fba&oe=58ACFF22&__gda__=1486855096_"}}},{"id":"901840776615466","name":"pqr","picture":{"data":{"is_silhouette":false,"url":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-xaf1\/v\/t1.0-1\/c0.0.50.50\/p50x50\/48142_460427077423507_21768463_n.jpg?oh=3801d55da3bca5a30546e627f3f068f9&oe"}}}],"paging":{"cursors":{"before":"QVFIUkdhcmpmOXdFVVRDSlppQjMxR0FEc2NTNW82bnQzaUZAFUmhmRUtqX0JaV25vV1pvalFoVm11clpvQm9tOXFsRkEZD","after":"QVFIUnZAsN0RReThOMkEyaUZAYQUJuVFRma0JiMU4wQXVGaTNTd2xORjlFdmpUR0FSOEtPbEw1WjMtRWhOMF82czZAWWVNWMktYMlV6Tzk4ZAGEwOUdNRllveGdB"}},"summary":{"total_count":6}}, error: null}
答案 0 :(得分:1)
如果您申请电子邮件许可,则无法保证您会收到电子邮件地址。例如,如果有人使用电话号码而不是电子邮件地址注册Facebook,则电子邮件字段可能为空。