Retrieve profile picture using Facebook SDK 3.0 for Android

前端 未结 6 1701
Happy的楠姐
Happy的楠姐 2021-02-19 03:24

I\'ve following problem with Facebook SDK 3.0 for Android. I wanna get my (and my friends) profile picture without using their ProfilePictureView widget, so if I use Graph Explo

6条回答
  •  一个人的身影
    2021-02-19 04:18

    You can retreive user information for executeMeRequest in facebook 3.0 sdk.
    
        public void executeMeRequest(Session session) {
    
            Bundle bundle = new Bundle();
            bundle.putString("fields", "picture");
            final Request request = new Request(session, "me", bundle,
                    HttpMethod.GET, new Request.Callback() {
    
                @Override
                public void onCompleted(Response response) {
                    GraphObject graphObject = response.getGraphObject();
                    if(graphObject != null) {
                        try {
                            JSONObject jsonObject = graphObject.getInnerJSONObject();
                            JSONObject obj = jsonObject.getJSONObject("picture").getJSONObject("data");
                            final String url = obj.getString("url");
                                new Thread(new Runnable() {
    
                                    @Override
                                    public void run() {
    
                                        final Bitmap bitmap = BitmapFactory.decodeStream(HttpRequest(url);
                                        runOnUiThread(new Runnable() {
    
                                            @Override
                                            public void run() {
                                                imageView.setImageBitmap(bitmap);
                                            }
                                        });
                                    }
                                }).start();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
            Request.executeBatchAsync(request);
        }
    
    public static InputStream HttpRequest(String strUrl) {
    
        HttpResponse responce = null;
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI(strUrl));
            responce = httpClient.execute(request);
            HttpEntity entity = responce.getEntity();
            return entity.getContent();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
        return null;
    }
    

提交回复
热议问题