如何使用图形API为Android获得的Facebook用户的位置 [英] how to get location of facebook user using Graph API for android

查看:290
本文介绍了如何使用图形API为Android获得的Facebook用户的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以用下面的code得到的姓名,电子邮件,性别和出生日期

I am able to get name,email,gender and birth date using the following code

loginButton.setReadPermissions(Arrays.asList(public_profile,电子邮件,user_birthday,user_friends,user_location)); //我还添加了user_location

loginButton.setReadPermissions(Arrays.asList("public_profile, email, user_birthday, user_friends,user_location")); //I also added user_location

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            GraphRequest request = GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object,GraphResponse response) {

                            Log.v("LoginActivity", response.toString());
                        }
                    });

            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,gender,birthday,location");   //and location parameter
            request.setParameters(parameters);
            request.executeAsync();


        }

        @Override
        public void onCancel() {
            // App code
            Log.v("LoginActivity", "cancel");
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            Log.v("LoginActivity", exception.getCause().toString());
        }
    });

但它只返回下列值。

but it only returns the following values.

07-22 12:53:05.639: E/Fb data(6560): {"id":"989472891104","name":"Karan Mer","email":"karan_mer2012@yahoo.co.in","gender":"male"}

我如何能得到在于:

how can I get that???

推荐答案

首先,您需要提供user_location为的

first of all you need to provide user_location for that

然后在

public void onCompleted(JSONObject object,GraphResponse response){

    JSONObject jsonObj = response.getGraphObject().getInnerJSONObject();
    GraphUser user = GraphObject.Factory.create(jsonObj,GraphUser.class);
    if (user.getLocation() != null && getLocation().getProperty("name")!= null) {
        userObject.userCity = user.getLocation().getProperty("name").toString();
    }
}

这工作对我来说,希望这对你的作品

this worked for me, hope this works for you

请注意:您可能必须做的,Facebook的审查,获取用户的位置

Note: You may have to do, the facebook review, for getting users location.

这篇关于如何使用图形API为Android获得的Facebook用户的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆