【Android】Facebook获取 user location

在request param里直接设置fields的参数串中添加location是不会生效的

//"fields"

    private static final String DEFAULT_REQUEST_VALUE = "id,name,location,link,picture,email,devices";

需要在登陆的Permission中添加”user_location”,如下:


List<String> permissions = Arrays.asList("user_location","public_profile");

        LoginManager.getInstance().logInWithReadPermissions(activity, permissions);

然后再在requestParam中添加fields的字段如前文所述:

 //send request and call graph api
                GraphRequest request = GraphRequest.newMeRequest(
                        accessToken,
                        new GraphRequest.GraphJSONObjectCallback() {

                            @Override
                            public void onCompleted(JSONObject object, GraphResponse response) {
                                HashMap<String, String> responseMap = new HashMap<>();

                                try {
                                    parseJSONResponse(object, responseMap);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                                final HashMap<String, String> postMap = responseMap;
                                // response callback
                                responseHelper.onSuccess(responseMap);

                            }
                        });

                // bundle the fields you want to get, sent the request
                Bundle parameters = new Bundle();
                if (TextUtils.isEmpty(paramsRequestKey) || TextUtils.isEmpty(paramsRequestKey)) {
                    setRequestParams();
                }

                parameters.putString(paramsRequestKey, paramsRequestValue);
                request.setParameters(parameters);
                request.executeAsync();

转载署源-By-KyleCe:http://blog.csdn.net/KyleCeshen/article/details/50381721

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值