使用setContentUrl()在Android上从Facebook共享

我在试图将应用程序中的内容分享到Facebook时遇到了一些麻烦。 我使用以下代码来执行此操作:

facebookButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if(ShareDialog.canShow(ShareLinkContent.class)){ ShareLinkContent linkContent=new ShareLinkContent.Builder() .setContentUrl(Uri.parse(imageUrls.get(0))) .build(); shareDialog.show(linkContent, ShareDialog.Mode.WEB); } } }); 

我的图片存储在Firebase存储中,我也可以在Facebook上发布,但标题和说明都设置为firebasestorage.googleapis.com,就像这个链接的图片: 分享post的屏幕截图

注意:不推荐使用setContentDescription()和setContentTitle()以及setImageUrl()。 有没有办法设置标题和共享post的描述?

FadyDev,我不知道你是否已经解决了你的问题,但这就是我所做的,而不是弃用的代码:

 // Builds the object ShareOpenGraphObject object = new ShareOpenGraphObject.Builder() .putString("fb:app_id", my_app_ID) .putString("og:url", link_to_site) .putString("og:type", objectType) .putString("og:title", contentTitle) .putString("og:description", contentDescription) .putString("og:image", imageLink) .build(); // Builds the action ShareOpenGraphAction action = new ShareOpenGraphAction.Builder() .setActionType(actionName) .putObject(objectName, object) .build(); // Create the openGraphContent ShareOpenGraphContent openGraphContent = new ShareOpenGraphContent.Builder() .setPreviewPropertyName(objectName) .setAction(action) .build(); return openGraphContent; 

在facebook doc中查看您要使用的操作以及相应的对象类型和所需参数。

https://developers.facebook.com/docs/sharing/opengraph/using-actions https://developers.facebook.com/docs/reference/opengraph

希望这可以帮助!