zoukankan      html  css  js  c++  java
  • [Android] how to get facebook profile

    Bundle params = new Bundle();
    params.putString("fields", "id,email,gender,cover,picture.type(large)");
    new GraphRequest(token, "me", params, HttpMethod.GET,
            new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {
                    if (response != null) {
                        try {
                            JSONObject data = response.getJSONObject();
                            if (data.has("picture")) {
                                String profilePicUrl = data.getJSONObject("picture").getJSONObject("data").getString("url");
                                Bitmap profilePic = getFacebookProfilePicture(profilePicUrl);
                                // set profilePic bitmap to imageview
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
    }).executeAsync();
    
    public static Bitmap getFacebookProfilePicture(String url){
        Bitmap bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
        return bitmap;
    }
    

    Or:

    GraphJSONObjectCallback mCallback = new GraphJSONObjectCallback()
    {
                @Override
                public void onCompleted(JSONObject mData, GraphResponse mResponse) 
                {
                    if(mResponse.getError() == null)
                    {   
                        try
                        {
                           final JSONObject mPicture = mData.getJSONObject("picture");                  
                           final JSONObject mPictureData = mPicture.getJSONObject("data");                  
                           final boolean mSilhouette = mPictureData.getBoolean("is_silhouette");                
    
                          **//this is the URL to the image that you want**
                          final String mImageUrl = mPictureData.getString("url"); 
                        }
    
                        catch (JSONException e)
                        {
                           //JSON Error, DEBUG
                        }
                    }
    
                    else
                    {
                         //Facebook GraphResponse error, DEBUG
                    }
               }
    }; 
    
    Bundle mBundle = new Bundle();
    mBundle.putString("fields", "picture");
    
    GraphRequest mGetUserRequest = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), mCallback);
    mGetUserRequest.setParameters(mBundle);
    
    //if running this on the MAIN THREAD then use .executeAsync()
    

      

    Or:

    private void importFbProfilePhoto() {
    
        if (AccessToken.getCurrentAccessToken() != null) {
    
            GraphRequest request = GraphRequest.newMeRequest(
                    AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject me, GraphResponse response) {
    
                            if (AccessToken.getCurrentAccessToken() != null) {
    
                                if (me != null) {
    
                                    String profileImageUrl = ImageRequest.getProfilePictureUri(me.optString("id"), 500, 500).toString();
                                    Log.i(LOG_TAG, profileImageUrl);
    
                                }
                            }
                        }
                    });
            GraphRequest.executeBatchAsync(request);
        }
    }

    refer to :http://stackoverflow.com/questions/19855072/android-get-facebook-profile-picture

  • 相关阅读:
    一种神奇的双向循环链表C语言实现
    ucore_lab0
    使用展开操符作替代 .apply() (prefer-spread)
    使用剩余参数代替 arguments (prefer-rest-params)
    LeetCode 11. Container With Most Water 单调队列
    Codecademy网站安利 及 javaScript学习
    谈项目团队分工角色和改进
    谈大型项目开发的多个环境配合
    以api文档为中心--前后端分开发离新思维
    中国进出口商品交易会开发总结
  • 原文地址:https://www.cnblogs.com/ryq2014/p/5201142.html
Copyright © 2011-2022 走看看