2

我正在使用最新的 Facebook 框架 3.1 创建 iOS 应用程序
我已经看到很多关于将图像和文本发布到 facebook 用户墙上的内容。我正在使用以下代码。

    NSDictionary* dict = @{
        @"link" : @"https://developers.facebook.com/ios",
        @"picture" : [UIImage imageNamed:@"Default"],
        @"message":@"Your temp message here",
        @"name" : @"MyApp",
        @"caption" : @"TestPost",
        @"description" : @"Integrating Facebook in ios"
    };
[FBRequestConnection startWithGraphPath:@"me/feed" parameters:dict HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    NSString *alertText;
    if (error)
    {
        NSLog(@"%@",[NSString stringWithFormat: @"error: domain = %@, code = %d", error.domain, error.code]);
        alertText = @"Failed to post to Facebook, try again";
    } else
    {
        alertText = @"Posted successfully to Facebook";
    }

    [[[UIAlertView alloc] initWithTitle:@"Facebook Result" message:alertText delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil] show];
}];

如果我将图片提供为“URL”,则它的发布很好。否则它的抛出错误。我想发布应用程序包中的图像。有人可以告诉我我在哪里编码错误吗?

4

1 回答 1

-1
UIImage* image = [UIImage imageNamed:@"nature.jpg"]; 

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"My First message" forKey:@"message"];    
[params setObject:image forKey:@"picture"];

[FBRequestConnection startWithGraphPath:@"me/photos" parameters:dict HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    NSString *alertText;
    if (error)
    {
 NSLog(@"%@",[NSString stringWithFormat: @"error: domain = %@, code = %d", error.domain, error.code]);
    alertText = @"Failed to post to Facebook, try again";
} else
{
    alertText = @"Posted successfully to Facebook";
}

[[[UIAlertView alloc] initWithTitle:@"Facebook Result" message:alertText delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil] show];
}];
于 2017-11-09T11:18:29.677 回答