我正在创建一个Android应用程序,我想使用其ShareOpenGraph功能将帖子分享到Facebook。我一直在关注FB提供的在线教程,实际上只是将其复制并粘贴到我的应用程序中(用于测试)。我有一个应用程序ID和所有内容。我可以发布其他类型的帖子,例如图像等,但是不能发布这种ShareOpenGraph类型的帖子。
当我从应用程序中单击“发布到Facebook”时,将弹出一个FB对话框,其中包含所有正确的信息,并且看起来很完美。
问题是,当我在Facebook的弹出对话框中单击“共享”时,出现一个Android错误,提示“ Facebook已停止”,并且我的帖子未发布到FB。
任何想法都会受到赞赏。
我的代码:(直接来自FB)
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "fitness.course")
.putString("og:title", "Sample Course")
.putString("og:description", "This is a sample course.")
.putInt("fitness:duration:value", 100)
.putString("fitness:duration:units", "s")
.putInt("fitness:distance:value", 12)
.putString("fitness:distance:units", "km")
.putInt("fitness:speed:value", 5)
.putString("fitness:speed:units", "m/s")
.build();
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("fitness.runs")
.putObject("fitness:course", object)
.build();
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("fitness:course")
.setAction(action)
.build();
ShareDialog.show(this, content);
和堆栈跟踪:
03-14 17:32:06.123 10816-10816/? E/fb4a.ACRA: ACRA caught a RuntimeException exception for com.facebook.katana version 143667885. Building report.
03-14 17:32:06.133 10816-10816/? E/fb4a.ACRA: Handling exception for crash
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=131, result=-1, data=Intent { (has extras) }} to activity {com.facebook.katana/com.facebook.platform.common.activity.PlatformWrapperActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.common.util.concurrent.ListenableFuture.addListener(java.lang.Runnable, java.util.concurrent.Executor)' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4920)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4963)
at android.app.ActivityThread.access$1600(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.common.util.concurrent.ListenableFuture.addListener(java.lang.Runnable, java.util.concurrent.Executor)' on a null object reference
at X.1jw.C(:112065)
at X.IVw.K(:2060973)
at X.IVP.A(:2059980)
at com.facebook.platform.common.activity.PlatformWrapperActivity.onActivityResult(:982510)
at android.app.Activity.dispatchActivityResult(Activity.java:7137)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4916)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4963)
at android.app.ActivityThread.access$1600(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)