现在的项目需求,增加了在Facebook上的分享。由于我们应用集成的是Facebook自身的SDK。在集成的时候碰到了很多坑,克服了很多困难。
下面就我记着的坑,罗列一下,具体解决方式暂不提供。
1.Facebook的集成包括了登录和分享。在做登录的时候,方法很简单,只要按照文档上的说明,调用即可。这里有一个小坑,在退出登录的时候,记得要调用一下Facebook的退出方法。否则会导致,Facebook无法切换账号。
2.Facebook的分享是真的坑,接入SDK的时候,千万要记住,按照文档一步步的接,认真看文档。
3.重点:Facebook最新版本不再支持预先设置文本,图片等分享预设的内容。如下就是Facebook的分享。
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(url))
.build();
那我们要怎么样设置分享的图片等内容呢。经过我的研究发现,Facebook通过另外一种方式,去展示分享。
<meta property="og:url" content="http://www.nytimes.com/2015/02/19/arts/international/when-great-minds-dont-think-alike.html" />
<meta property="og:type" content="article" />
<meta property="og:title" content="When Great Minds Don’t Think Alike" />
<meta property="og:description" content="How much does culture influence creative thinking?" />
<meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" />
property="og:url" content="http://www.nytimes.com/2015/02/19/arts/international/when-great-minds-dont-think-alike.html" />
<meta property="og:type" content="article" />
<meta property="og:title" content="When Great Minds Don’t Think Alike" />
<meta property="og:description" content="How much does culture influence creative thinking?" />
<meta property="og:image" content="http://static01.nyt.com/images/2015/02/19/arts/international/19iht-btnumbers19A/19iht-btnumbers19A-facebookJumbo-v2.jpg" />
我们的html源码中,设置这些标签,可以设置出对应的预览内容。这里就强调一个image。图片必须大于200*200。否则会从html 中随机拿一张图作为缩略图。
4.做分享测试的时候,由于国内不允许Facebook,我们需要翻墙使用。这里就是一个坑了,注意。一定不要总是切换VPN,分享出去的图片一定要设置仅自己可见。
否则,我们开发组加测试,被封了10几个号了。。。
5.另外的应该都不是问题