在Facebook上发布带有文本的图像

时间:2013-04-18 10:37:03

标签: ios facebook-graph-api

我想使用后备分享在Facebook上发布Feed。它应该包含图像和消息。我通过更改参数来尝试太多了

 NSMutableDictionary *postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
 @"http://www.abc.com",@"link",
 self.produtObj.productImageURL, @"picture",
 self.produtObj.productName, @"name",
 self.produtObj.productDescription, @"message",
 nil];

[FBRequestConnection
 startWithGraphPath:@"me/feed"
 parameters:postParams
 HTTPMethod:@"POST"
 completionHandler:^(FBRequestConnection *connection,
                     id result,
                     NSError *error) {
     NSString *alertText;
     if (error) {
         alertText = [NSString stringWithFormat:
                      @"error: domain = %@, code = %d",
                      error.domain, error.code];
     } else {
         alertText = [NSString stringWithFormat:
                      @"Posted action, id: %@",
                      [result objectForKey:@"id"]];
     }
     // Show the result in an alert
     [[[UIAlertView alloc] initWithTitle:@"Result"
                                 message:alertText
                                delegate:self
                       cancelButtonTitle:@"OK!"
                       otherButtonTitles:nil]
      show];
 }];

使用此代码,Feed会显示在一个框中,单击它会将我带到指定的链接。我只是希望有一个带有故事的图像缩略图,因为它不在盒子里面。请帮我。这是我在SOF中的第一个问题。所以请原谅我的错误。 提前致谢。 :)

1 个答案:

答案 0 :(得分:1)

我更喜欢使用UIActivityItemViewConroller将内容推送到Facebook。

用户需要在他们的设备上登录Facebook。你可以通过Facebook部分的设置来做到这一点。

我为我的东西制作了这样的新控制器:

    NSMutableArray *stuff = [[NSMutableArray alloc]init];
    NSString *textstring = @"Now is the time for all good men to come to the aid of their country. Lorum Ipsum etc";
    UIImage *pic = [UIImage imageNamed:@"Icon-Small-50"];//A local image
    NSString *URL = @"http://nwc.co/images/nwc-icon-200.gif";//A link to an image
    [stuff addObject:textstring];
    [stuff addObject:pic];
    [stuff addObject:URL];
    UIActivityViewController *vc = [[UIActivityViewController alloc]initWithActivityItems:stuff applicationActivities:nil];

    [self.navigationController presentViewController:vc animated:YES completion:^{
        //do something here when they are done   
    }];

如果您运行上述操作,您会注意到文本,本地图像和在线图像的链接都显示在帖子上。 如果您不想在弹出活动图标时混淆人们,则可以排除其他活动:

vc.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo, UIActivityTypeMail, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];