简体   繁体   English

Facebook SDK 4.0.1无法在Android Studio中获得某些字段

[英]Facebook sdk 4.0.1 can't get some fields with Android studio

I am working on a login function with facebook for my android app. 我正在为我的Android应用程序使用Facebook登录功能。

I have almost everything done but i can't get all the fields. 我几乎完成了所有工作,但无法获得所有领域。

Im getting only something in fullname and the fbid. 我只得到一些全名和fbid。

First name, Gender, Profile picture returns nothing. 名字,性别,个人资料图片不返回任何内容。

  GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject fbUser,
                                                GraphResponse response) {

                            final ParseUser parseUser = ParseUser.getCurrentUser();
                            try{
                                parseUser.fetchIfNeeded();
                            }catch (Exception e){}

                            if (fbUser != null && parseUser != null
                                    && fbUser.optString("name").length() > 0) {
                                Log.d("fb","Json--"+fbUser);
                                parseUser.put(USER_OBJECT_NAME_FIELD, fbUser.optString("first_name"));
                                   parseUser.put("fullname",fbUser.optString("name"));
                            try{
                                   String mm= fbUser.getString("email");
                                    parseUser.setEmail(mm);
                                }catch (Exception e){//e.printStackTrace();
                                  }
                                   try{
                                    String mm= fbUser.getString("gender");
                                    if(mm.equals("male"))
                                    {

For profile pic i'm using this: 对于个人资料照片,我正在使用此:

          try {
                                    final String id = fbUser.getString("id");
                                    parseUser.put("fbId", id);

                                    //Your code goes here
                                    String ur = "https://graph.facebook.com/" + id + "/picture?width=640&height=640";
                                    ImageLoader imageLoader = ImageLoader.getInstance();
                                    imageLoader.init(ImageLoaderConfiguration.createDefault(getActivity().getApplicationContext()));
                                    imageLoader.loadImage(ur, new SimpleImageLoadingListener() {
                                        @Override
                                        public void onLoadingComplete(String imageUri, View view, Bitmap bmImg) {
                                            // Do whatever you want with Bitmap
                                            if(bmImg!=null) {
                                                bmImg=Bitmap.createScaledBitmap(bmImg,640,640,false);
                                                ParseFile dL = new ParseFile("dpLarge.jpg", bmImg.toString().getBytes());
                                                Bitmap smal = Bitmap.createScaledBitmap(bmImg, 120, 120, false);
                                                ParseFile ds = new ParseFile("dpSmall.jpg", smal.toString().getBytes());
                                                parseUser.put("dpLarge", dL);
                                                parseUser.put("dpSmall", ds);
                                            }

Permissions: 权限:

      facebookLoginButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            loadingStart(false); // Facebook login pop-up already has a           spinner
            if (config.isFacebookLoginNeedPublishPermissions()) {
                  ParseFacebookUtils.logInWithPublishPermissionsInBackground(getActivity(),
                        config.getFacebookLoginPermissions(), facebookLoginCallbackV4);
            } else {
                ParseFacebookUtils.logInWithReadPermissionsInBackground(getActivity(),
                        config.getFacebookLoginPermissions(), facebookLoginCallbackV4);
            }
        }
    });
}

Can't figure out what im doing wrong. 无法弄清楚我在做什么错。

I haven't already used facebook sdk, but according to your problem with a profile picture, did you tried solutions from these posts: 我还没有使用过facebook sdk,但是根据您的个人资料图片问题,您是否尝试过以下文章的解决方案:

How to get facebook profile picture of user in facebook SDK 3.0 Android 如何在Facebook SDK 3.0 Android中获取用户的Facebook个人资料图片

How to get facebook profile picture of user in facebook SDK Android 如何在Facebook SDK Android中获取用户的Facebook个人资料图片

Try also to use some logs for example to check if String ur appears correctly. 还尝试使用一些日志,例如检查String ur是否正确显示。

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

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