如何在Android上处理Facebook ShareDialog.canShow()== false [英] How to handle Facebook ShareDialog.canShow() == false on Android

查看:651
本文介绍了如何在Android上处理Facebook ShareDialog.canShow()== false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook的在Android上共享文档告诉我们使用以下代码片段显示ShareDialog如果(ShareDialog.canShow(ShareLinkContent.class)){
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle(Hello Facebook)
.setContentDescription(
Hello Facebook示例展示了简单的Facebook集成)
.setContentUrl(Uri.parse(http: //developers.facebook.com/android))
.build();

shareDialog.show(linkContent);
}

我的问题是为什么我们需要检查ShareDialog.canShow()?在什么情况下这可能返回false,我们需要处理这种情况?

解决方案

昨天我花了很多时间尝试调试错误与此相关。 Facebook的文档在这个意义上很差,当与这个 canShow()方法有一个错误时,它只是默默地失败,没有记录。



所以,回答你的问题:


我的问题是为什么我们需要检查ShareDialog.canShow ()?在
的情况下,这可能返回false,我们需要处理
这种情况​​吗?


基于我遇到的情况:当用户没有在他们的设备上安装Facebook应用,并且想要分享照片( SharePhotoContent )或视频( ShareVideoContent ), canShow()将返回 false 。原因是Facebook SDK的WebView版本不支持共享这种内容。



我发现这是调试他们的 FacebookActivity class,在 handlePassThroughError()方法中。 (未记录)错误消息是:



无法显示提供的内容,这通常意味着Facebook应用程序未安装或更新。如果通过网络显示,这可能意味着该内容的属性不通过此频道支持。



那么我们应该怎么办当 canShow()返回 false



这取决于你的情况。可能的解决方案是:


  1. 显示对话框(或SnackBar),告诉用户他们需要安装Facebook应用程序才能共享这种内容;

  2. 请求身份验证令牌,使用Facebook SDK登录用户,并使用自己的对话框直接分享内容并调用Facebook API。

可能的Facebook解决方案将包括在他们的文档中或在LogCat上记录此错误。



希望它有帮助!


Facebook's Sharing on Android documentation tells us to show the ShareDialog with the following code snippet:

if (ShareDialog.canShow(ShareLinkContent.class)) {
    ShareLinkContent linkContent = new ShareLinkContent.Builder()
            .setContentTitle("Hello Facebook")
            .setContentDescription(
                    "The 'Hello Facebook' sample  showcases simple Facebook integration")
            .setContentUrl(Uri.parse("http://developers.facebook.com/android"))
            .build();

    shareDialog.show(linkContent);
}

My question is why do we need to check ShareDialog.canShow()? In what scenarios would this possibly return false and do we need to handle this scenario? The example code would just fail silently not tell the user anything.

解决方案

I spent a lot of time yesterday trying to debug an error related to this. Facebook's docs are poor in this sense and when there is an error related to this canShow() method, it just fails silently, no logging at all.

So, to answer your question:

My question is why do we need to check ShareDialog.canShow()? In what scenarios would this possibly return false and do we need to handle this scenario?

Based on the scenario I faced: when the user doesn't have the Facebook app installed on their device and you want to share photos (SharePhotoContent) or videos (ShareVideoContent), canShow() will return false. The reason is that Facebook SDK's WebView version doesn't support sharing this kind of content.

I found this out debugging their FacebookActivity class, on the handlePassThroughError() method. The (not logged) error message is:

"Unable to show the provided content. This typically means that the Facebook app is not installed or up to date. If showing via the Web, this could mean that the content has properties that are not supported via this channel."

So, what should we do when canShow() returns false?

It depends on your scenario. Possible solutions would be:

  1. Show a dialog (or SnackBar) telling the user that they need to install the Facebook app to be able to share this kind of content;
  2. Request an authentication token, log the user using the Facebook SDK, and share the content using your own dialog and calling Facebook API directly.

Possible solutions for Facebook would be include this on their documentation or log this error on LogCat.

Hope it helps!

这篇关于如何在Android上处理Facebook ShareDialog.canShow()== false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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