2012-06-01 147 views
1

我想在成功登錄後使用以下代碼發表評論。在Facebook上發表評論

public void postOnWall(String msg) { 
     Log.d("Tests", "Testing graph API wall post"); 
     //byte[] by_new = msg.getBytes(); 
     try { 
       String response = mFacebook.request("me"); 
       Bundle parameters = new Bundle(); 
       parameters.putString("message", msg); 
       parameters.putString("description", "test test test"); 
       response = mFacebook.request("me/feed", parameters, 
         "GET"); 
       Log.d("Tests", "got response: " + response); 
       if (response == null || response.equals("") || 
         response.equals("false")) { 
        Log.v("Error", "Blank response"); 
       } 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 

logcat的:

06-01 17:51:44.042: DEBUG/Tests(623): got response: {"data":[]} 

但是,當我使用GET方法我接收到空白響應和當我用POST方法我接收到以下的反應。

06-01 18:04:26.522: WARN/Bundle(676): Key message expected byte[] but value was a java.lang.String. The default value <null> was returned. 
06-01 18:04:26.532: WARN/Bundle(676): Attempt to cast generated internal exception: 
06-01 18:04:26.532: WARN/Bundle(676): java.lang.ClassCastException: java.lang.String 
06-01 18:04:26.532: WARN/Bundle(676):  at android.os.Bundle.getByteArray(Bundle.java:1305) 
06-01 18:04:26.532: WARN/Bundle(676):  at com.facebook.android.Util.openUrl(Util.java:156) 
06-01 18:04:26.532: WARN/Bundle(676):  at com.facebook.android.Facebook.request(Facebook.java:559) 
06-01 18:04:26.532: WARN/Bundle(676):  at com.kmiller.facebookintegration.Login.postOnWall(Login.java:108) 
06-01 18:04:26.532: WARN/Bundle(676):  at com.kmiller.facebookintegration.Login$1.onClick(Login.java:78) 
06-01 18:04:26.532: WARN/Bundle(676):  at android.view.View.performClick(View.java:2485) 
06-01 18:04:26.532: WARN/Bundle(676):  at android.view.View$PerformClick.run(View.java:9080) 
06-01 18:04:26.532: WARN/Bundle(676):  at android.os.Handler.handleCallback(Handler.java:587) 
06-01 18:04:26.532: WARN/Bundle(676):  at android.os.Handler.dispatchMessage(Handler.java:92) 
06-01 18:04:26.532: WARN/Bundle(676):  at android.os.Looper.loop(Looper.java:123) 
06-01 18:04:26.532: WARN/Bundle(676):  at android.app.ActivityThread.main(ActivityThread.java:3647) 
06-01 18:04:26.532: WARN/Bundle(676):  at java.lang.reflect.Method.invokeNative(Native Method) 
06-01 18:04:26.532: WARN/Bundle(676):  at java.lang.reflect.Method.invoke(Method.java:507) 
06-01 18:04:26.532: WARN/Bundle(676):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
06-01 18:04:26.532: WARN/Bundle(676):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
06-01 18:04:26.532: WARN/Bundle(676):  at dalvik.system.NativeStart.main(Native Method) 
+1

http://stackoverflow.com/questions/3726429/post-message-to-facebook-wall -from-android-fb-sdk-always-error/3927541#3927541 – Akram

+0

對此行的評論String response = mFacebook.request(「me」);並檢查它,因爲我已經回答 – Khan

+0

@Akki謝謝,但現在回覆:06-01 18:33:46.452:調試/測試(843):得到的迴應:{「error」:{「message」:「(#200)用戶沒有授權應用程序執行此操作「,」type「:」OAuthException「,」code「:200}} –

回答

1

試試這個,我認爲如u已經把 「GET」,而不是 「POST」

String response = facebook.request("me/feed", parameters,"POST"); 
+0

我嘗試了GET和POST。使用POST錯誤發生在上面發佈。 –

+0

對此行的評論String response = mFacebook.request(「me」);而不是像我回答那樣檢查它 – Khan

相關問題