我想在 Facebook 墙上发布一些带有图像的文字。我有来自图形 API 的代码,它可以执行此操作,但我想从捆绑包中发布我的图像,而不是像此 API 那样从链接中发布图像。谁能告诉我如何发布你自己的图片而不是链接
"[variables setObject:@"http://bit . ly/bFTnqd" forKey:@"link"];"
在 Facebook 墙上。
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:4];
[variables setObject:@"this is a test message: postMeFeedButtonPressed" forKey:@"message"];
UIImage *picture = [UIImage imageNamed:@"forest fog.jpg"];
[variables setObject:@"http://bit . ly/bFTnqd" forKey:@"link"];
[variables setObject:@"This is the bolded copy next to the image" forKey:@"name"];
[variables setObject:@"This is the plain text copy next to the image. All work and no play makes Jack a dull boy." forKey:@"description"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/feed" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed: %@", fb_graph_response.htmlResponse);
//parse our json
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];
//let's save the 'id' Facebook gives us so we can delete it if the user presses the 'delete /me/feed button'
self.feedPostId = (NSString *)[facebook_response objectForKey:@"id"];
NSLog(@"feedPostId, %@", feedPostId);
NSLog(@"Now log into Facebook and look at your profile...");
您将图像隐藏为数据并将其添加为字典中的另一个参数(键“数据”的数据值)。我在这里给出了示例
[variables setObject:imageData forKey:@"data"];
其他变更
UIImage *picture = [UIImage imageNamed:@"forest fog.jpg"];
NSData *imageData = UIImageJPEGRepresentation(picture, 10);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"your caption message",@"message",
imageData,@"data",
nil];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:@"me/photos" withPostVars:variables];
NSLog(@"postMeFeedButtonPressed: %@", fb_graph_response.htmlResponse);
以下代码应该可以解决您的问题...
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Photo uploaded.\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"\",\"href\":\"%@/\"}]}",PhotoSourceURL];
[dialog show];
让我知道,它对你有用吗...
编辑: