我想在成功登录后使用以下代码在墙上发表评论。
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)
答案 0 :(得分:1)
尝试这个我认为你已经把“GET”而不是“POST”
String response = facebook.request("me/feed", parameters,"POST");