我们在我们的react应用程序和我们的本地Android应用程序的web版本中这样做,所以我们的设置和一切都很好。我正在尝试实现在react中共享一个操作--使用react本机-fbsdk。我遵循的是Android代码,因为它看起来最接近于react本机-fbsdk代码。
我应该使用ShareApi.share还是其他什么的?
我尝试创建一个ShareOpenGraphContent实例以与ShareApi.share一起使用,但是没有构造函数。
我希望他们能提供更详尽的文件:
基于我的同事在Android上使用的ShareApi代码,它似乎缺少了一些与共享操作相关的内容。
ShareOpenGraphContent不是从react本机fbsdk直接导出的,因此
import { ShareOpenGraphContent } from 'react-native-fbsdk';实际上不起作用。必须有某种方法来使用react中的ShareApi --本机-fbsdk来共享一个操作……我只是遗漏了一些东西。
有人help...please。
谢谢!!
发布于 2016-11-28 18:50:27
我想出来了!我必须手动创建ShareOpenGraphContent对象的实例,该实例具有3个强制属性: contentType、action和previewPropertyName。react本机-fbsdk目前没有此对象类型的构造函数。
ShareApi.canShare不是强制性的,但它检查以确保您在尝试共享之前拥有正确的权限。这将允许您在尝试之前让用户登录,以防他们的令牌过期,或者用户尚未同意所需的权限。
const ogAction = new ShareOpenGraphAction('<your_facebook_namespace>' + ':' + '<your_facebook_action>');
ogAction.putString('song', 'https://<url_to_your_song_app_etc>');
ogAction.putString('place', '<fbPlacePageID>'');
ogAction.putNumber('fb:explicitly_shared', 1); // Normally this is a boolean, but putNumber with a value of 1 works
// Manually create an instance of ShareOpenGraphContent (no constructor in the API)
const ogContent = {
contentType: 'open-graph',
action: ogAction,
previewPropertyName: 'song',
};
ShareApi.canShare(ogContent).then((canShare) => {
if (canShare)
return ShareApi.share(ogContent, '/me');
}).then(
function(result) {
// Shared successfully
},
function(error) {
// Failed to share
}
);https://stackoverflow.com/questions/40812963
复制相似问题