簡體   English   中英

iOS Facebook分享

[英]iOS Facebook share

在獲得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];
  }

您要共享兩次相同的內容,這可能是為什么您無法通過一張圖像獲得一個狀態消息(而是獲得兩個)的原因:

[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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM