简体   繁体   English

在下一个活动android中使用facebook sdk 4.0.1登录后获取用户配置文件

[英]get userprofile after login with facebook sdk 4.0.1 in next activity android

My application allows the user to connect with Facebook. 我的应用程序允许用户连接Facebook。 I want to get userprofile information after login with Facebook (using Facebook SDK 4.0.1). 我想userprofile与Facebook登录信息后(使用Facebook的SDK 4.0.1)。 I think that I should use aynctask to get it but I don't know how. 我认为我应该使用aynctask来获取它,但是我不知道如何。

loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>()
    {
        @Override
        public void onSuccess(LoginResult loginResult)
        {
            System.out.println("onSuccess");
            msginfo.setText("You can now share image on facebook");
            otherview.setVisibility(View.VISIBLE);

            GraphRequest request = GraphRequest.newMeRequest
                    (loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback()
                    {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response)
                        {
                            // Application code
                            Log.v("LoginActivity", response.toString());
                            //System.out.println("Check: " + response.toString());
                            try
                            {
                                String id = object.getString("id");
                                idT.setText(object.getString("id"));
                                ppv.setProfileId(object.getString("id"));
                                nameT.setText(object.getString("name"));
                                emailT.setText(object.getString("email"));
                                locationT.setText(object.getString("address"));

                                String name = object.getString("name");
                                String email = object.getString("email");
                                String gender = object.getString("gender");
                                String birthday = object.getString("birthday");
                                // String location = object.getString("location");
                                // String location = object.getString("user_location");
                                // String location = object.getString("address");




                                System.out.println(id + ", " + name + ", " + email + ", " + gender + ", " + birthday);
                                // locationT.setText(location);

                            }
                            catch (JSONException e)
                            {
                                e.printStackTrace();
                            }

                        }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,gender, birthday,link");
            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());
        }
    });

And I can get the profile informations in the current activity but not in the next one. 而且我可以在当前活动中获取个人资料信息,但不能在下一个活动中获取。

I think you are missing permissions 我认为您缺少权限

parameters.putString("fields", "id,name,email,gender,picture,birthday");

And then you can easily get profile pic 然后您可以轻松获取个人资料照片

object.getJSONObject("picture").getJSONObject("data").getString("url");

Hope it helps. 希望能帮助到你。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM