2015-10-28 140 views
2

我想獲取頁面的個人資料圖片。 這是代碼,但我不知道如何獲得的圖像:獲取頁面個人資料圖片圖形API android

new GraphRequest(AccessToken.getCurrentAccessToken(), 
       "/174034509278825/picture", 
       null, 
       HttpMethod.GET, 
       new GraphRequest.Callback() 
       { 
        public void onCompleted(GraphResponse response) { 
         try { } 
         catch (JSONException e) 
         { 
          e.printStackTrace(); 
         } 
         } 

       }  
       ).executeAsync(); 

回答

1

響應JSON中獲取資料圖片:

{ 
    "data": { 
    "is_silhouette": false, 
    "url": "picture-url" 
    }, 
} 

我的解決辦法代碼:

AccessToken accessToken = new AccessToken({access-token} 
         , {app-id}, {user-id} 
         , null, null, null, null, null); 

       GraphRequest request = GraphRequest.newGraphPathRequest(
         accessToken, 
         "/{user-id}/picture", 
         new GraphRequest.Callback() { 
          @Override 
          public void onCompleted(GraphResponse response) { 
           try { 
            JSONObject responseJSONObject = response.getJSONObject(); 
            JSONObject data = responseJSONObject.getJSONObject("data"); 

            Log.i("your tag", "picture url = "+data.getString("url")); 
           } catch (JSONException e) { 
            e.printStackTrace(); 
           } 
          } 
         }); 

       Bundle parameters = new Bundle(); 
       parameters.putString("redirect", "false"); 
       request.setParameters(parameters); 
       request.executeAsync(); 
+0

它的工作原理, 謝謝。 –

相關問題