如何在facebook登录android时获得电子邮件权限?

时间:2015-03-15 08:45:49

标签: android facebook facebook-graph-api nullpointerexception

我正在构建一个Android应用程序,我正在使用facebook登录。当我的手机中安装了facebook应用程序时,代码工作得很好。 现在的问题是,当我的手机中没有安装facebook应用程序时,应用程序会匆忙检索邮件ID。

这是我的fb登录代码 -

onCreateView -

loginBtn.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            if (user != null) {

                // getting name of the user
                name = user.getName();

                // getting email of the user
                email = user
                        .getProperty("email")
                        .toString();

                // getting gender of the user
                id = user.getId();

                URL image_value = null;
                try {
                    image_value = new URL("https://graph.facebook.com/" + id + "/picture");
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }

                profile_pic_url = image_value.toString();


                Intent gps = new Intent(getApplicationContext(), GPS.class);

                // store string value
                editor.putString("fblogout", "1"); // Storing string
                editor.putString("name", name); // Storing string
                editor.putString("mail_id", email);
                editor.putString("id", id);
                editor.putString("profile_pic_url", profile_pic_url);
                editor.commit();
                startActivity(gps);

            } else {

            }
        }
    });

onSession Open -

private Session.StatusCallback statusCallback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
                 Exception exception) {
    if (state.isOpened()) {
        buttonsEnabled(true);



    } else if (state.isClosed()) {
        buttonsEnabled(false);

    }
}
};

    public boolean checkPermissions() {
    Session s = Session.getActiveSession();
    if (s != null) {
        return s.getPermissions().contains("publish_actions");
    } else
        return false;
}

public void requestPermissions() {
    Session s = Session.getActiveSession();
    if (s != null)
        s.requestNewPublishPermissions(new Session.NewPermissionsRequest(
                this, PERMISSIONS));
}

错误日志 -

    at com.facebook.Request$1.onCompleted(Request.java:283)
at com.facebook.Request$4.run(Request.java:1668)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5034)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案