2017-02-26 69 views
0

我使用Java從Facebook圖形API獲取用戶提要。 /我/飼料工作正常,但我想獲得帖子的圖片,如果可用。 在圖形API資源管理器,下面的網址運作正常檢索圖片:facebook api獲取圖片提要

/我/飼料領域=圖片,消息,故事

但是,當我改變我的代碼:?

final GraphRequest graphRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/feed", null, HttpMethod.GET, gCallback); 

final GraphRequest graphRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/feed?fields=message,story", null, HttpMethod.GET, gCallback); 

它從RuntimeException的崩潰:

02-26 16:30:34.751: D/AndroidRuntime(28980): Shutting down VM 
02-26 16:30:34.751: E/AndroidRuntime(28980): FATAL EXCEPTION: main 
02-26 16:30:34.751: E/AndroidRuntime(28980): Process: com.aktuna.gear.facebook, PID: 28980 
02-26 16:30:34.751: E/AndroidRuntime(28980): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity {com.aktuna.gear.facebook/com.aktuna.gear.facebook.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.app.ActivityThread.deliverResults(ActivityThread.java:4925) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4968) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.app.ActivityThread.access$1600(ActivityThread.java:222) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1849) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.os.Handler.dispatchMessage(Handler.java:102) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.os.Looper.loop(Looper.java:158) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.app.ActivityThread.main(ActivityThread.java:7229) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at java.lang.reflect.Method.invoke(Native Method) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
02-26 16:30:34.751: E/AndroidRuntime(28980): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.json.JSONArray.length()' on a null object reference 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.aktuna.gear.facebook.MainActivity$1.onSuccess(MainActivity.java:71) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.aktuna.gear.facebook.MainActivity$1.onSuccess(MainActivity.java:1) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.facebook.login.LoginManager.finishLogin(LoginManager.java:508) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:192) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:140) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:82) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at com.aktuna.gear.facebook.MainActivity.onActivityResult(MainActivity.java:107) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.app.Activity.dispatchActivityResult(Activity.java:7137) 
02-26 16:30:34.751: E/AndroidRuntime(28980): at android.app.ActivityThread.deliverResults(ActivityThread.java:4921) 
02-26 16:30:34.751: E/AndroidRuntime(28980): ... 9 more 

有什麼不對? 爲什麼圖形請求返回null,如果我添加字段到我的請求?

感謝

+0

可能是你的SDK需要以不同的方式指定的字段。你檢查過文件嗎? – CBroe

+0

該文檔沒有提供關於從/ me/feed獲取圖片的任何線索。或者我不明白?這裏只有幾個字:https://developers.facebook.com/docs/graph-api/reference/v2.8/user/feed –

+0

您正在混淆API和SDK。 – CBroe

回答

0

感謝@CBroe我能找到的SDK參考示例答案。

這裏是未來場合:

GraphRequest request = GraphRequest.newMeRequest(
     accessToken, 
     new GraphRequest.GraphJSONObjectCallback() { 
      @Override 
      public void onCompleted(
        JSONObject object, 
        GraphResponse response) { 
       // Application code 
      } 
     }); 
Bundle parameters = new Bundle(); 
parameters.putString("fields", "id,name,link"); 
request.setParameters(parameters); 
request.executeAsync();