Facebook Android:分享图片和链接

时间:2015-10-02 07:17:02

标签: android facebook

我需要使用Facebook分享图片和链接。

似乎不可能。

有明确的答案吗?

6 个答案:

答案 0 :(得分:7)

Quoting from developers.facebook.com:

Links

When people share links from your app to Facebook, it includes attributes that show up in the post:

  • a contentURL, the link to be shared
  • a contentTitle that represents the title of the content in the link
  • a imageURL, the URL of thumbnail image that will appear on the post
  • a contentDescription of the content, usually 2-4 sentences

If you want to display also the image you should use setImageUrl(@Nullable final Uri imageUrl):

ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(contentUrl))
                .setImageUrl(Uri.parse(imageUrl))
                .build();

The result will be something like this:

enter image description here

答案 1 :(得分:2)

答案 2 :(得分:1)

你想做的是这样吗?

enter image description here

如果是这样,可以使用Facebook SDK。这是示例代码。

Bitmap image = ...
SharePhoto photo = new SharePhoto.Builder()
        .setBitmap(image)
        .build();
SharePhotoContent content = new SharePhotoContent.Builder()
        .addPhoto(photo)
        .build();

此链接可能对您有所帮助。 https://developers.facebook.com/docs/sharing/android

答案 3 :(得分:0)

您是否尝试过Facebook SDK Documentation

中描述的内容
ShareLinkContent linkContent = new ShareLinkContent.Builder()
                        .setContentTitle("Title")
                        .setContentUrl(Uri.parse("http://www.yoururl.com"))
                        .setImageUrl(Uri.parse("http://www.yourserver.com/image.jpg"))
                        .build();

shareDialog.show(linkContent);

答案 4 :(得分:0)

如果您想要链接,请参阅此官方文档:
https://developers.facebook.com/docs/sharing/android
在那里你会找到分享链接内容部分:

ShareLinkContent content = new ShareLinkContent.Builder()
        .setContentUrl(Uri.parse("https://developers.facebook.com"))
        .build();


在那里你会找到分享图片部分:

Bitmap image = ...
SharePhoto photo = new SharePhoto.Builder()
        .setBitmap(image)
        .build();
SharePhotoContent content = new SharePhotoContent.Builder()
        .addPhoto(photo)
        .build();

在这里你可以找到一个例子:
http://simpledeveloper.com/how-to-share-an-image-on-facebook-in-android/

答案 5 :(得分:0)

@Lisa Anne

要分享 text,images,link 等内容,我们需要使用ShareLinkContent class。我们可以使用 setContentUrl(), setContentTitle(), setContentDescription() 方法设置要分享的网址,标题和说明。

如何致电

ShareLinkContent content = new ShareLinkContent.Builder().build();
Your_Dialog_Obj.show(content);

其类简短示例

public final class ShareLinkContent
extends ShareContent<ShareLinkContent, ShareLinkContent.Builder> {
private final String contentDescription;
private final String contentTitle;
private final Uri imageUrl;

private ShareLinkContent(final Builder builder) {
    super(builder);
    this.contentDescription = builder.contentDescription;
    this.contentTitle = builder.contentTitle;
    this.imageUrl = builder.imageUrl;
}

ShareLinkContent(final Parcel in) {
    super(in);
    this.contentDescription = in.readString();
    this.contentTitle = in.readString();
    this.imageUrl = in.readParcelable(Uri.class.getClassLoader());
}

/**
 * The description of the link.  If not specified, this field is automatically populated by
 * information scraped from the link, typically the title of the page.
 * @return The description of the link.
 */
public String getContentDescription() {
    return this.contentDescription;
}

礼貌归developers.facebook.com。    因此,您可以轻松了解传递imageURLcontentDescription

演示示例

ShareLinkContent linkContent = new ShareLinkContent.Builder()
            .setContentUrl(Uri.parse(contentUrl))
            .setImageUrl(Uri.parse(imageUrl))
            .build();
  

如果您的应用分享指向iTunes或Google Play商店的链接,我们则不会   发布您在共享中指定的任何图像或说明。代替   我们会直接从应用商店发布一些应用信息   使用Webcrawler。这可能不包括图像。预览链接   分享到iTunes或Google Play,在URL调试器中输入您的URL。

将照片的共享内容构建到SharePhotoContent模型中。有关所有属性的列表,请参阅SharePhotoContent参考。

Bitmap image = ...
SharePhoto photo = new SharePhoto.Builder()
        .setBitmap(image)
        .build();
SharePhotoContent content = new SharePhotoContent.Builder()
        .addPhoto(photo)
        .build();
  

Android Facebook API and ShareLinkContent

用于理解目的的Git演示。

  1. FacebookImageShareIntent
相关问题