繁体   English   中英

Facebook iOS SDK 4.0上的显式共享

[英]Explicit Sharing on Facebook iOS SDK 4.0

我想使用新的iOS 4.0 SDK在Facebook上明确分享一个开放的图形动作。 以下不起作用。 它显示在我的活动日志中,但不显示在我的时间轴上。

// Construct an FBSDKSharePhoto
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = img;
photo.userGenerated = YES;

// Create an object
NSDictionary *properties = @{
                             @"og:type": @"theprose:post",
                             @"og:title": post.title,
                             @"og:description": post.text,
                             @"og:caption": @"A fresh picked Prose for you.",
                             @"og:url": post.url,
                             @"fb:explicitly_shared": @"true"
                             };
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];

// Create an action
FBSDKShareOpenGraphAction *act = [[FBSDKShareOpenGraphAction alloc] init];
act.actionType = @"theprose:share";
[act setObject:object forKey:@"theprose:post"];
[act setPhoto:photo forKey:@"image"];

// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = act;
content.previewPropertyName = @"theprose:post";

[[FBSDKShareAPI shareWithContent:content delegate:nil] share];

拼凑这个页面的答案,这对我有用:

1.选中“明确共享”框

转到打开的图表设置,操作类型,然后选择自定义操作。 向下滚动到功能部分,确保选中“显式共享”框。

功能设置

2.设置fb:explicitely_shared On Action

[action setString:@"true" forKey:@"fb:explicitly_shared"];

3.设置动作和对象之间的关系

确保您知道将操作连接到对象的正确方法。 在这种情况下,关键是“文章”:

[FBSDKShareOpenGraphAction actionWithType:@"mynamespace:share" object:object key:@"article"]

您可以通过查看在FB应用程序的Open Graph设置中创建的Action Type来找到该键。 当您通过Story将Action与Ob​​ject连接时,该关系的新键将显示在Property Name列的Action页面上。

原始海报使用namespace:property_name格式,而您真正需要的只是该键的property_name。 这可能是OP的修复。

4.设置代理,查找错误

OP没有利用FBSDKSharingDelegate功能。 它会报告错误并帮助您解决问题:

[[FBSDKShareAPI shareWithContent:content delegate:self] share];

并在self中实现委托方法:

#pragma mark - FBSDKSharingDelegate

- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results {

    NSLog(@"Facebook sharing completed: %@", results);
}

- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {

    NSLog(@"Facebook sharing failed: %@", error);
}

- (void) sharerDidCancel:(id<FBSDKSharing>)sharer {

    NSLog(@"Facebook sharing cancelled.");
}

供参考,这是我的工作代码

    // Create the object
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: @{
                                                                                   @"og:type": @"mynamespace:article",
                                                                                   @"og:title": myModel.title,
                                                                                   @"og:description": @"myModel.description",
                                                                                   @"og:url": @"http://mywebsite.com"
                                                                                   }];


NSURL *imageURL = [myModel getImageURL];
if (imageURL) {

    FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWithImageURL:imageURL userGenerated:NO];
    [properties setObject:@[photo] forKey:@"og:image"];
}

FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];

// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"mynamespace:share" object:object key:@"article"];
[action setString:@"true" forKey:@"fb:explicitly_shared"];

// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";

// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;

[shareAPI share];

同样的问题但在同一帐户下使用FBSDKShareDialog可以正常工作。 所以问题出在其他方面。

我遇到了同样的问题。 我的意思是你的代码中的原因是你在对象中设置fb:explicit_shared属性而不是在关注动作中。

以下代码应该可以解决问题。

[action setString:@"true" forKey:@"fb:explicitly_shared"];
  1. 如果您的Facebook应用程序不公开,请确保在“角色”部分中将测试帐户添加为测试帐户。

  2. 确保您已请求publish_actions权限: https//developers.facebook.com/docs/facebook-login/ios/permissions

  3. 您没有为您的电话分配代表,很有可能您没有收到Facebook返回的错误

转到打开的图表设置,操作类型,然后选择自定义操作。 向下滚动到功能部分,确保选中“显式共享”框。

在此输入图像描述

它应该不起作用,因为在4.1版本之前的FB版本中存在一个错误: https//developers.facebook.com/bugs/943100005734949/ https://developers.facebook.com/bugs/1563738347248670但是SDK版本4.1这个错误是修复的,但与FSDKShareDialog相比,自定义故事/动作/对象的内容以非常不同的方式显示(((

再检查清单:FBSDKShareApi仅适用于主线程。 因此,请确保您从那里分享。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM