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

  • 相关阅读:
    整除15问题
    软件工程基础Proposal提议
    对在大学阶段软件工程实践的一些想法
    运行web项目端口占用问题
    Day_1
    error C3615: constexpr 函数 "QAlgorithmsPrivate::qt_builtin_ctz" 不会生成常数表达式
    Qt应用程序的打包
    将html代码部署到阿里云服务器,并进行域名解析,以及在部署过程中遇到的问题和解决方法
    linux部署html代码到linux服务器,并进行域名解析
    运行sudo apt-get install nginx时报错有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?解决
  • 原文地址:https://www.cnblogs.com/ryq2014/p/5201142.html
Copyright © 2011-2022 走看看