无法从facebook图表api sdk v4中检索用户地址

时间:2015-07-29 10:06:43

标签: android facebook facebook-graph-api

是否需要从facebook图表api获取用户地址的权限。

我能够检索id,名称,电子邮件,链接,区域设置,时区,但json对象中没有地址。

请查看我的代码:

    private void getFacebookuserData(AccessToken token) {
    GraphRequest request = GraphRequest.newMeRequest(accessToken,
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object,
                        GraphResponse response) {
                    /**
                     * In JSONObject user_name,user_id, user_email of user
                     * logedIn.
                     */

                    try {
                        mEmail = object.getString("email");
                        appPreference.setEmail(mEmail);
                        appPreference.setFacebookemail(mEmail);
                        mUserId = object.getString("id");
                        mUserName = object.getString("name");
                        appPreference.setName(mUserName);
                        CustomAsynTask asyncTask = new CustomAsynTask(
                                HomeActivity.this, "sociallogin", "", true);
                        asyncTask.setListener(HomeActivity.this);
                        asyncTask.execute();
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields",
            "id,name,email,address,link,locale,timezone");
    request.setParameters(parameters);
    request.executeAsync();
}

2 个答案:

答案 0 :(得分:0)

试试这个:

String name,email,key;
GraphLocation address;

private void getFacebookUserInfo() {

    Session.openActiveSession(this, true, new Session.StatusCallback() {

        @Override
        public void call(final Session sess, SessionState state,
                Exception exception) {
            session=sess;
            System.out.println("ssssssssss"+session+"    "+state);
            if (session.isOpened()) {

                        Request.newMeRequest(session,new GraphUserCallback() {
                        @Override
                        public void onCompleted(final GraphUser user,Response response) {


                            System.out.println("uuuuuuuuuuu    "+user);

                        if (user != null) {
                        try{

                        name = user.getFirstName()+" "+user.getLastName();
                        email = user.getEmail();
                        key = session.getAccessToken();
                        address = user.getLocation();

                        System.out.println("name======="+name);
                        System.out.println("email======="+email);
                        System.out.println("key========="+key);

                        Intent intent=new Intent(Sign_In.this,Mobile_Verification.class);
                        startActivity(intent);
                        finish();

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

                        }
                    }
            }).executeAsync();


            } else {
                System.out.println("elseeeeeeeeee");

                OpenRequest op = new Session.OpenRequest(Sign_In.this);


                List<String> permissions = new ArrayList<String>();
                op.setPermissions(permissions);
                session = new Builder(Sign_In.this).build();
                session.openForRead(op);

            }
        }
    });

答案 1 :(得分:0)

Facebook有关于此的官方文档请尝试这样 希望你会好的

  

https://developers.facebook.com/docs/graph-api/reference/user