在我的Android应用程序中,我正在尝试共享包含对象和动作的开放图表
在我的Facebook应用程序中,我添加了一个故事:action="take"
和object="photo"
(这可以吗?)。
当我尝试将图像添加到OG中的对象时,我得到了上述错误。
这是我的代码:
private void shareWithFacebookOpenGraph(String pathToImage) {
Log.i("SHARE", "1. share with OpenGraph");
OpenGraphObject photo = OpenGraphObject.Factory.createForPost("myapp:photo");
photo.setProperty("title", "MyApp Photo");
photo.setProperty("image", "http://play.google.com/to_my_app_launcher_icon");
photo.setProperty("url", "http://play.google.com/to_my_app");
photo.setProperty("description", "Image taken with myApp for Android");
List<File> files = new ArrayList<File>();
files.add(new File(pathToImage));
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setProperty("photo", photo);
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(this, action, "myapp:take", "photo")
.setImageAttachmentFilesForObject("photo", files, true) // **Error**
.build();
uiHelper.trackPendingDialogCall(shareDialog.present());
}
这是logcat:
08-12 04:26:48.780: mypackage.myapp: fatal error : Can't create Collection from java.lang.String
08-12 04:26:48.780: com.facebook.FacebookGraphObjectException: Can't create Collection from java.lang.String
08-12 04:26:48.780: at com.facebook.model.GraphObject$Factory.coerceValueToExpectedType(GraphObject.java:371)
08-12 04:26:48.780: at com.facebook.model.GraphObject$Factory$GraphObjectProxy.proxyGraphObjectGettersAndSetters(GraphObject.java:675)
08-12 04:26:48.780: at com.facebook.model.GraphObject$Factory$GraphObjectProxy.invoke(GraphObject.java:523)
08-12 04:26:48.780: at $Proxy2.getImage(Native Method)
08-12 04:26:48.780: at com.facebook.widget.FacebookDialog$OpenGraphDialogBuilderBase.updateObjectAttachmentUrls(FacebookDialog.java:1386)
08-12 04:26:48.780: at com.facebook.widget.FacebookDialog$OpenGraphDialogBuilderBase.setImageAttachmentFilesForObject(FacebookDialog.java:1364)
08-12 04:26:48.780: at com.facebook.widget.FacebookDialog$OpenGraphActionDialogBuilder.setImageAttachmentFilesForObject(FacebookDialog.java:1)
08-12 04:26:48.780: at mypackage.myactivity.shareWithFacebookOpenGraph(EnhancedCameraPreviewActivity.java:3247)
08-12 04:26:48.780: at mypackage.myactivity.access$155(EnhancedCameraPreviewActivity.java:3224)
08-12 04:26:48.780: at mypackage.myactivity$89.onClick(EnhancedCameraPreviewActivity.java:3184)
08-12 04:26:48.780: at android.view.View.performClick(View.java:4438)
08-12 04:26:48.780: at android.view.View$PerformClick.run(View.java:18422)
08-12 04:26:48.780: at android.os.Handler.handleCallback(Handler.java:733)
08-12 04:26:48.780: at android.os.Handler.dispatchMessage(Handler.java:95)
08-12 04:26:48.780: at android.os.Looper.loop(Looper.java:136)
08-12 04:26:48.780: at android.app.ActivityThread.main(ActivityThread.java:5017)
08-12 04:26:48.780: at java.lang.reflect.Method.invokeNative(Native Method)
08-12 04:26:48.780: at java.lang.reflect.Method.invoke(Method.java:515)
08-12 04:26:48.780: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-12 04:26:48.780: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-12 04:26:48.780: at dalvik.system.NativeStart.main(Native Method)
我做错了什么? 也许我在故事中弄乱了一些字符串,facebook教程很糟糕!
答案 0 :(得分:1)
您已经在照片对象中设置了图片。如果您以后要将图像添加为附件,请删除该行。