简体   繁体   English

在Android中,Facebook API V2.4不返回电子邮件ID,而V2.3返回。 如何在V2.4中获取电子邮件ID?

[英]In Android, Facebook API V2.4 is not returning email id whereas V2.3 is returning. How to get email id in V2.4?

When I wrote the following code for API V2.3 this was giving me all details including email id. 当我为API V2.3编写以下代码时,这为我提供了所有详细信息,包括电子邮件ID。 And now the same code is not giving me email id. 现在,相同的代码没有给我发送电子邮件ID。 What can I can do to get email id? 我该怎么办才能获得电子邮件ID?

    oncreate(..)
    {
    .
    .    
    EMAIL_PERMISSION = new ArrayList<String>();
    EMAIL_PERMISSION.add("email");
    uiLifecycleHelper = new UiLifecycleHelper(this, statusCallback);

    uiLifecycleHelper.onCreate(savedInstanceState);

   Session.openActiveSession(this, true, EMAIL_PERMISSION,   
                                          statusCallback);
    // callback when session changes state
Session.StatusCallback statusCallback = new StatusCallback()
{
    @Override
    public void call(Session session, SessionState state, Exception  
                                                         exception)
    {

        // Checking whether the session is opened or not
        if (state.isOpened())
        {
        } else
        {
            if (state.isClosed())
            {
            }
            Log.d(TAG, state.toString());
        }
    }
};
 // Method to get user facebook profile
void getUserFacebookProfile(Session session, final boolean finish)
{
    // Checking whether the session is opened or not
    if (session.isOpened())
    {
        // Sending request to the facebook to get user facebook profile
        Request.newMeRequest(session, new GraphUserCallback()
        {

            @Override
            public void onCompleted(GraphUser user, Response response)
            {

                if (user != null)
                {
                    // To get network user id
                    String networkUserid = user.getId();
                    // To get user first name
                    String fname = user.getFirstName();
                    // To get user last name
                    String lname = user.getLastName();
                    // To get user middle name
                    String mname = user.getMiddleName();
                // String email = user.getProperty("email").toString();
    String email = response.getGraphObject().getProperty("email")
                     .toString();
                }

Now the above code gave me all details including email id for V2.3, now i'm not able to get email id. 现在,上面的代码为我提供了所有详细信息,包括V2.3的电子邮件ID,现在我无法获取电子邮件ID。 Please let me know solution. 请让我知道解决方案。 Thanks. 谢谢。

public class LoginFacebook {
    CallbackManager callbackManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();


    public void openFB() {
            LoginManager.getInstance().logInWithReadPermissions(activity,
                    Arrays.asList("read_stream", "user_photos", "email", "user_location"));

            // Login Callback registration
            LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

                @Override
                public void onSuccess(final LoginResult loginResult) {
                    new GraphRequest(AccessToken.getCurrentAccessToken(),
                            "/me", null, HttpMethod.GET,
                            new GraphRequest.Callback() {
                                public void onCompleted(
                                        GraphResponse response) {
                                    /* handle the result */

                                    try {
                                        //GET USER INFORMATION
                                        JSONObject json = response.getJSONObject();
                                        String email = json.getString("email");
                                        String fullName = json.getString("name");
                                        String accessToken = loginResult.getAccessToken().getToken();
                                        int type = 1;
                                        String lastUpdate = json.getString("updated_time");
                                        String user_id = json.getString("id");

                                    } catch (JSONException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                }
                            }).executeAsync();

                    GetSnsPost getSnsPost = GetSnsPost.getInstance(activity);
                    getSnsPost.getFacebookPosts();

                }

                @Override
                public void onCancel() {

                }

                @Override
                public void onError(FacebookException exception) {

                }
            });

        }

     public void loginFacebook(View v){
           openFB();
     }
     protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        callbackManager.onActivityResult(requestCode, resultCode, data);

    }
    }

Since session have been deprecated long time ago, I don't use it anymore. 由于会话很久以前已被弃用,因此我不再使用它。 I get user information this way. 我通过这种方式获取用户信息。 Hope this code will solve your problem ;) 希望这段代码能解决您的问题;)

Bundle params = new Bundle(); Bundle参数= new Bundle(); params.putString("fields", "id,name,email,birthday,first_name,last_name"); params.putString(“ fields”,“ id,name,email,birthday,first_name,last_name”);

new GraphRequest( AccessToken.getCurrentAccessToken(), AccessToken.getCurrentAccessToken().getUserId(), params, HttpMethod.GET, new GraphRequest.Callback() { 新的GraphRequest(AccessToken.getCurrentAccessToken(),AccessToken.getCurrentAccessToken()。getUserId(),params,HttpMethod.GET,新的GraphRequest.Callback(){

                                @Override
                                public void onCompleted(
                                        GraphResponse response) {

                                    System.out.println("\n J S O N :"
                                            + response.toString());


                                    } catch (JSONException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                }
                            }).executeAsync();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Facebook API版本v2.4获取用户电子邮件和生日 - How to get user email and birthday from Facebook API Version v2.4 从Graph API v2.4开始,针对用户ID /相册的GET请求应包含一个明确的“字段”参数 - starting with Graph API v2.4, GET requests for user-id/album should contain an explicit “fields” parameter 通过Facebook登录解析 - 可能是自APK v42或Graph API v2.4 - Parse with Facebook login - Possibly since APK v42 or Graph API v2.4 Facebook Graph Api v 2.4 - Facebook Graph Api v 2.4 Android Studio中的Facebook SDK 4 ExceptionInitializeError登录v2.3 - Facebook SDK 4 in Android Studio ExceptionInitializeError Login v2.3 发布Facebook(v2.3)对来自Android的好友发布的评论 - Publishing Facebook (v2.3) comment on friends post from Android 在Android中使用图形API v2.3获取朋友的个人资料图片网址或个人资料图片 - get friend's profile picture url or profile picture using graph api v2.3 in android Facebook Android SDK v2.3对LoginManager.onActivityResult的意外调用 - Facebook Android SDK v2.3 Unexpected call to LoginManager.onActivityResult IllegalArgumentException:无法在Android Studio v2.3中找到adb - IllegalArgumentException: Unable to locate adb in Android Studio v2.3 Android v2.3可以播放MP4文件吗? - Can Android v2.3 Play MP4 files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM