如果您使用的是最新的Facebook 的 iOS SDK http://thinkdiff.net/facebook/how-to-develop-facebook-application-for-iphone/然后使用下面的方法您可以将图像发布为流。
- (IBAction) publishStream: (id)sender {
SBJSON *jsonWriter = [[SBJSON new] autorelease];
NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
@"Always Running",@"text",@"http://thinkdiff.net",@"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary* imageShare = [NSDictionary dictionaryWithObjectsAndKeys:
@"image", @"type",
@"http://thinkdiff.net/mahmud_small.jpg", @"src",
@"http://thinkdiff.net", @"href",
nil];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
@"a long run", @"name",
@"The Facebook Running app", @"caption",
@"it is fun", @"description",
@"http://itsti.me/", @"href",
[NSArray arrayWithObjects:imageShare, nil ], @"media",
nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSLog(attachmentStr);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"api_key",
@"Share on Facebook", @"user_message_prompt",
actionLinksStr, @"action_links",
attachmentStr, @"attachment",
nil];
[_facebook dialog: @"stream.publish"
andParams: params
andDelegate:self];
}
图像部分应该是另一个 NSDictionary 对象。
NSDictionary* imageShare = [NSDictionary dictionaryWithObjectsAndKeys:
@"image", @"type",
@"http://thinkdiff.net/mahmud_small.jpg", @"src",
@"http://thinkdiff.net", @"href",
nil];
并且在附件中 NSDictionary 对象必须包含 imageShare 对象作为数组
[NSArray arrayWithObjects:imageShare, nil ]
这是因为如果您不将其包含为数组,Json 解析器会避免使用 [] 括号,因此发布功能将无法工作。请记住,该字符串必须是有效的 JSON 字符串,否则 facebook api 将不会发布。