我想使用新的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];
答案 0 :(得分:9)
将这个页面的答案拼凑在一起,这对我有用:
<强> 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与Object连接时,该关系的新键将显示在Property Name列的Action Name页面上。
原始海报使用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];
答案 1 :(得分:1)
同样的问题但在同一帐户下使用FBSDKShareDialog可以正常工作。所以问题出在其他方面。
答案 2 :(得分:0)
如果您的Facebook应用不公开,请确保在“角色”部分中将测试帐户添加为测试帐户。
确保您已请求publish_actions权限: https://developers.facebook.com/docs/facebook-login/ios/permissions
您没有为您的通话分配代表,很可能您没有收到Facebook返回的错误
答案 3 :(得分:0)
转到打开的图表设置,操作类型,然后选择自定义操作。向下滚动到功能部分,确保&#34;明确分享&#34;框已选中。
答案 4 :(得分:0)
它应该不起作用,因为在4.1版之前的SDK版本中存在一个错误: https://developers.facebook.com/bugs/943100005734949/ https://developers.facebook.com/bugs/1563738347248670 但是使用SDK版本4.1时,这个错误已得到修复,但与FSDKShareDialog相比,自定义故事/动作/对象的内容以非常不同的方式显示((
答案 5 :(得分:0)
再次检查清单:FBSDKShareApi仅适用于主线程。所以请确保你从那里分享。