没有从android中的fb sdk收到电子邮件

时间:2015-10-24 06:54:33

标签: android facebook email facebook-graph-api

我已尝试多次使用不同的代码,但我仍然没有收到来自fb登录的电子邮件。请帮助我麻烦拍摄isseu。此外,我在我的测试fb帐户上收到了2封电子邮件,但仍然没有收到任何电子邮件。代码贴在下面。

public class fbpage extends Activity {

String get_id, get_name, get_gender, get_email, get_birthday,get_locale, get_location,id;
private TextView info;
private LoginButton loginButton;
private CallbackManager callbackManager,mCallbackManager;
private static final String TAG = "FacebookConnect";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.fbpagelayout);
    callbackManager = CallbackManager.Factory.create();

    loginButton = (LoginButton) findViewById(R.id.login_button);
   // List<String> permissionNeeds = Arrays.asList("user_photos","email","user_birthday", "public_profile", "AccessToken");
    loginButton.registerCallback(callbackManager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {

                    System.out.println("onSuccess");

                    String accessToken = loginResult.getAccessToken()
                            .getToken();
                    Log.i("accessToken", accessToken);

                    GraphRequest request = GraphRequest.newMeRequest(
                            loginResult.getAccessToken(),
                            new GraphRequest.GraphJSONObjectCallback() {
                                @Override
                                public void onCompleted(JSONObject object,
                                                        GraphResponse response) {
                                    Log.i("LoginActivity", response.toString());
                                    try {
                                        id = object.getString("id");
                                        try {
                                            URL profile_pic = new URL(
                                                    "http://graph.facebook.com/" + id + "/picture?type=large");
                                            Log.i("profile_pic",
                                                    profile_pic + "");

                                        } catch (MalformedURLException e) {
                                            e.printStackTrace();
                                        }
                                        String name = object.getString("name");
                                        String email = object.getString("email");
                                        String gender = object.getString("gender");
                                        //String birthday = object.getString("birthday");
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
                    Bundle parameters = new Bundle();
                    parameters.putString("fields",
                            "id,name,email,gender, birthday");
                    request.setParameters(parameters);
                    request.executeAsync();
                }

                @Override
                public void onCancel() {
                    System.out.println("onCancel");
                }

                @Override
                public void onError(FacebookException exception) {
                    System.out.println("onError");
                    Log.v("LoginActivity", exception.getCause().toString());
                }
            });


}

@Override
protected void onActivityResult(int requestCode, int responseCode,
                                Intent data) {
    super.onActivityResult(requestCode, responseCode, data);
    callbackManager.onActivityResult(requestCode, responseCode, data);
}

}

1 个答案:

答案 0 :(得分:0)

您需要添加需要的权限代码。

List<String> permissionNeeds = Arrays.asList("user_photos", "email", "user_birthday", "public_profile", "user_location"); 
mButtonLogin.setReadPermissions(permissionNeeds); 

添加这两行后,您将获得访问电子邮件ID的权限。