如何获得用户电子邮件的GraphRequest.newMeRequest [英] How to get user email on GraphRequest.newMeRequest

查看:774
本文介绍了如何获得用户电子邮件的GraphRequest.newMeRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序Facebook的登录选项,我想失败获取用户的电子邮件。 在登录之后,用户,并添加到Parse.com用户表(凭有效的访问令牌),我要求的Facebook用户信息,但只得到它的ID和姓名(即使该邮件被设置为权限之一)。

下面是我的code(内OnClickListener我的按钮):

  ParseFacebookUtils.logInWithReadPermissionsInBackground(
    getActivity(),Arrays.asList(电子邮件,user_friends),新LogInCallback(){
        @覆盖
        公共无效完成(ParseUser用户,ParseException的错误){
            //犯错是空

            如果(用户== NULL){
                Log.d(TAG,啊哦用户取消了Facebook登录。);
            } 其他 {
                GraphRequest.newMeRequest(
                    AccessToken.getCurrentAccessToken(),
                    新GraphRequest.GraphJSONObjectCallback(){
                        @覆盖
                        公共无效onCompleted(JSONObject的用户,GraphResponse响应){

                            Log.d(TAG,用户=+ user.toString());
                            //输出 - >用户= {名:my_fb_name,ID:my_fb_id}
                        }
                    }
                ).executeAsync();
           }
       });
 

解决方案

我想这是关系到图形API V2.4的变化,你指定你想从图形API返回的各个领域,这使得有必要

有一个在我的答案在

  • <一个href="http://stackoverflow.com/questions/31692355/facebook-only-returning-name-and-id-of-user/31692908#31692908">Facebook仅返回名称和用户ID

有关本

至于你的实际问题,请参阅

  • <一个href="https://developers.facebook.com/docs/android/graph#userdata">https://developers.facebook.com/docs/android/graph#userdata

有关如何指定字段的一个例子的 GraphRequest

  GraphRequest请求= GraphRequest.newMeRequest(
        访问令牌,
        新GraphRequest.GraphJSONObjectCallback(){
            @覆盖
            公共无效onCompleted(
                   的JSONObject对象,
                   GraphResponse响应){
                //应用code
            }
        });
捆绑参数=新包();
parameters.putString(域,ID,姓名,电子邮件);
request.setParameters(参数);
request.executeAsync();
 

I have a Facebook login option in my Android app and I am trying to get the user's email unsuccessfully. After the user is logged in, and added to the Parse.com User table (with a valid access token), I request the Facebook user info, but only get it's id and name (even though the email is set as one of the permissions).

Here's my code (inside OnClickListener of my button):

ParseFacebookUtils.logInWithReadPermissionsInBackground(
    getActivity(), Arrays.asList("email", "user_friends"), new LogInCallback() {
        @Override
        public void done(ParseUser user, ParseException err) {
            //err is null

            if (user == null) {
                Log.d(TAG, "Uh oh. The user cancelled the Facebook login.");
            } else {
                GraphRequest.newMeRequest(
                    AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject user, GraphResponse response) {

                            Log.d(TAG, "user = " + user.toString());
                            //prints -> user = {"name":"my_fb_name","id":"my_fb_id"}
                        }
                    }
                ).executeAsync();                
           }
       });

解决方案

I guess this is related to a change in the Graph API v2.4 which makes it necessary that you specify every field you want to have returned from the Graph API.

Have a look at my answer at

regarding this

Concerning your actual problem, see

for an example on how to specify the fields for a GraphRequest

GraphRequest request = GraphRequest.newMeRequest(
        accessToken,
        new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(
                   JSONObject object,
                   GraphResponse response) {
                // Application code
            }
        });
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();

这篇关于如何获得用户电子邮件的GraphRequest.newMeRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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