Android:Facebook SDK 4.x中的共享对话框类是什么

前端之家收集整理的这篇文章主要介绍了Android:Facebook SDK 4.x中的共享对话框类是什么前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用下面的代码打开Facebook页面URL的Facebook共享对话框.

问题是,当我通过Facebook应用程序查看我墙上的共享帖子时,我发现没有共享页面封面的帖子.

如果我通过我的墙上的Facebook应用程序共享同一页面,我会找到带有共享页面封面的帖子(当然这更酷).

下面的代码中是否缺少参数?

我正在使用Facebook SDK 4.1.2

FacebookDialog shareDialog = new ShareDialog(mMainActivity);
    if (ShareDialog.canShow(ShareLinkContent.class))
    {
        ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(aFacebookPageURL))
                .build();


        shareDialog.show(linkContent);
    }

编辑1:

使用.setImageUrl(Uri.parse(aPageCoverURL))

您可以看到上半部分(通过Facebook移动应用程序共享)和下半部分(通过我的应用程序共享)之间的差异.

编辑2:如何使用以下代码共享Facebook页面?下面的代码不起作用,没有出现共享对话框,我不知道是否有缺少参数或者此代码不是为了共享页面,但我正在尝试.

ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type","page")
            .putString("og:title",aTitle)
            .putString("og:url",aURL)
            .build();

    // Create an action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType(null)
            .putObject("page",object)
            .build();

    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("page")
            .setAction(action)
            .build();

    ShareDialog.show(mMainActivity,content);

解决方法

来自Facebook documentation

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

如果要显示图像,则应使用setImageUrl(@Nullable final Uri imageUrl)

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

这是SDK的一个分享

这是一个直接来自应用程序的共享:

原文链接:https://www.f2er.com/android/314658.html

猜你在找的Android相关文章