iOS Facebook分享

时间:2015-07-09 09:26:51

标签: ios facebook

获得grantPermissions" publish_actions"后,现在我希望用户希望用户在不留当前视图的情况下将消息和图像(本地生成的)发送到他们的Facebook时间线。

我尝试过 FBSDKShareAPI 界面,但这不是我想要的效果。我希望用一条消息和一个图像实现一个状态。我该怎么办?

FBSDKSharePhoto* photo = [[FBSDKSharePhoto alloc]init];
photo.image = self.shareImage;
photo.userGenerated = YES;

FBSDKSharePhotoContent * content = [[FBSDKSharePhotoContent alloc]init];
content.photos = @[photo];

if ([[FBSDKAccessToken currentAccessToken].permissions containsObject:@"publish_actions"]) {
    FBSDKShareAPI * shareApi = [[FBSDKShareAPI alloc]init];
    shareApi.message = self.tf.text;
    [shareApi createOpenGraphObject:object];
    [FBSDKShareAPI shareWithContent:content delegate:self];
    [shareApi share];
  }

1 个答案:

答案 0 :(得分:4)

您正在两次共享相同的内容,这可能是您无法通过一个图片获取一个状态消息(而是获得两个)的原因:

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

你可能不需要为它创建一个开放的图形对象。试试这个:

NSURL *imageURL = [NSURL URLWithString:@"https://upload.wikimedia.org/wikipedia/en/d/d3/Nasa_mer_marvin.jpg"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]]; // taking image from Wikipedia for example purposes
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = image; // photo.image = self.shareImage;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
if ([[FBSDKAccessToken currentAccessToken].permissions containsObject:@"publish_actions"]) {
    FBSDKShareAPI * shareApi = [[FBSDKShareAPI alloc]init];
    shareApi.message = @"Lorem Ipsum Dolor Sit Amet"; // shareApi.message = self.tf.text;
    shareApi.shareContent = content;
    [shareApi share];
}