我正在开发一个与 Facebook SDK 集成的 Android 应用程序。
首先,我正在使用 Graph API 获取 Facebook 页面的提要,它运行良好。我想允许用户喜欢并针对每个提要发表评论。
我正在为Like使用以下代码片段
Bundle parameters = new Bundle();
parameters.putString("access_token", access_token);
String response = null;
String id = <Target Feed ID>;
try {
response = facebook.request(id+"/likes", parameters, "POST");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i("FB Like Output", ""+response);
但我在以下行得到 NullPointerException:
response = facebook.request(id+"/likes", parameters, "POST");
请注意,仅当我使用“POST”或“DELETE”作为第三个参数时才会出现此错误。相反,如果我使用 GET 我会得到正确的响应(但是,这不会满足我的目的)。
此外,我还添加了相关权限,例如publish_stream。
这是使用 HTTP POST 方法发出同步请求的正确语法吗?
04-25 16:29:08.332: E/AndroidRuntime(710): FATAL EXCEPTION: main
04-25 16:29:08.332: E/AndroidRuntime(710): java.lang.NullPointerException
04-25 16:29:08.332: E/AndroidRuntime(710): at java.net.URLDecoder.decode(URLDecoder.java:130)
04-25 16:29:08.332: E/AndroidRuntime(710): at java.net.URLDecoder.decode(URLDecoder.java:68)
04-25 16:29:08.332: E/AndroidRuntime(710): at com.facebook.android.Util.openUrl(Util.java:186)
04-25 16:29:08.332: E/AndroidRuntime(710): at com.facebook.android.Facebook.requestImpl(Facebook.java:806)
04-25 16:29:08.332: E/AndroidRuntime(710): at com.facebook.android.Facebook.request(Facebook.java:794)
04-25 16:29:08.332: E/AndroidRuntime(710): at com.test.myapp.adapters.FacebookAdapter$1.onClick(FacebookAdapter.java:107)
04-25 16:29:08.332: E/AndroidRuntime(710): at android.view.View.performClick(View.java:2408)
04-25 16:29:08.332: E/AndroidRuntime(710): at android.view.View$PerformClick.run(View.java:8816)
04-25 16:29:08.332: E/AndroidRuntime(710): at android.os.Handler.handleCallback(Handler.java:587)
04-25 16:29:08.332: E/AndroidRuntime(710): at android.os.Handler.dispatchMessage(Handler.java:92)
04-25 16:29:08.332: E/AndroidRuntime(710): at android.os.Looper.loop(Looper.java:123)
04-25 16:29:08.332: E/AndroidRuntime(710): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-25 16:29:08.332: E/AndroidRuntime(710): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 16:29:08.332: E/AndroidRuntime(710): at java.lang.reflect.Method.invoke(Method.java:521)
04-25 16:29:08.332: E/AndroidRuntime(710): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-25 16:29:08.332: E/AndroidRuntime(710): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-25 16:29:08.332: E/AndroidRuntime(710): at dalvik.system.NativeStart.main(Native Method)