我正在使用最新的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”提供,则其发布正常。否则它的投掷错误。我想发布应用程序包中的图像。有人可以告诉我我的编码错误吗?
答案 0 :(得分:-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];
}];