安卓:什么是Facebook的SDK 4.x中的比重对话框类 [英] Android: What is the share dialog class in Facebook SDK 4.x

查看:334
本文介绍了安卓:什么是Facebook的SDK 4.x中的比重对话框类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是code以下,打开一个Facebook页面的URL Facebook分享对话框。

现在的问题是,当我看就通过Facebook应用我的墙上共享后,我发现没有共享页盖的职位。

而如果我分享通过Facebook应用程序在同一页上我的墙上,我发现后与共享页盖(这当然是冷得多)。

有以下code缺少的参数?

我使用Facebook的SDK 4.1.2

  FacebookDialog shareDialog =新ShareDialog(mMainActivity);
    如果(ShareDialog.canShow(ShareLinkContent.class))
    {
        ShareLinkContent linkContent =新ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(aFacebookPageURL))
                。建立();


        shareDialog.show(linkContent);
    }
 

编辑1:

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

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

编辑2:我怎么可以使用下面的code分享Facebook页面?下面的code不工作,也不会出现共享对话框,我不知道是否有遗漏的参数或该code并不意味着分享网页,但我想。

  ShareOpenGraphObject对象=新ShareOpenGraphObject.Builder()
            .putString(OG:类型,网页)
            .putString(OG:标题,aTitle)
            .putString(OG:URL,aURL)
            。建立();

    //创建一个动作
    ShareOpenGraphAction行动=新ShareOpenGraphAction.Builder()
            .setActionType(空)
            .putObject(页,对象)
            。建立();

    ShareOpenGraphContent内容=新ShareOpenGraphContent.Builder()
            .SET previewPropertyName(网页)
            .setAction(动作)
            。建立();

    ShareDialog.show(mMainActivity,内容);
 

解决方案

从Facebook的文档

  

链接

     

当您的应用程序,Facebook的人分享链接,它包括   这显示了在后属性:

     
      
  • contentURL ,要共享的链接
  •   
  • contentTitle 的再presents内容的标题中的链接
  •   
  • IMAGEURL 的缩略图的URL将出现在后
  •   
  • contentDescription 的内容,通常是2-4个句子
  •   

如果你想显示你应该使用像<一个href="https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/share/model/ShareLinkContent.java#L139-L142"相对=nofollow> setImageUrl(@Nullable最终乌里IMAGEURL):

  ShareLinkContent linkContent =新ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(aFacebookPageURL))
                .setImageUrl(Uri.parse(IMAGEURL))
                。建立();
 

这是从SDK共享:

这是直接的比例从应用程序:

I'm using the code below to open Facebook share dialog with a Facebook page URL.

The problem is, when I look to the shared post on my wall via Facebook application, I find the post without the shared page cover.

While if I shared the same page via Facebook application on my wall, I find the post with the shared page cover (Which of course is much cooler).

Is there a missing parameters in the code below?

I'm using 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);
    }

Edit 1:

using .setImageUrl(Uri.parse(aPageCoverURL))

You can see the difference between the upper half (shared via Facebook app for mobile) and the bottom half (shared via my application).

Edit 2: How can I use the code below to share a Facebook page? The code below is not working and no share dialog appears, I don't know if there is a missing parameters or this code is not meant to share pages, but I'm trying.

    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);

解决方案

From the 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

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

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

This is a share from SDK:

This is a share directly from the app:

这篇关于安卓:什么是Facebook的SDK 4.x中的比重对话框类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆