我正在尝试在Facebook上发布字符串消息,但它只发布用户的消息类型而不是附件字符串。我该怎么办?
- (void)postToWall {
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
NSString *joke = @"Hello i am happy";
dialog.userMessagePrompt = @"Enter your message:";
dialog.attachment = [NSString stringWithFormat:@"{\"name\":,\"%@ Posted Message!}",
facebookName, joke];
[dialog show];
}
答案 0 :(得分:1)
NSString *customMessage = [NSString stringWithFormat:@"CUSTOM MESSAGE"];
NSString *postName = @"SAMPLE_APP";
NSString *serverLink = [NSString stringWithFormat:@"http://www.google.co.in "];
NSString *imageSrc = @"PATH OR URL TO IMAGE";
NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] init]autorelease];
[dictionary setObject:postName forKey:@"name"];
[dictionary setObject:serverLink forKey:@"href"];
[dictionary setObject:customMessage forKey:@"description"];
NSMutableDictionary *media = [[[NSMutableDictionary alloc] init]autorelease];
[media setObject:@"image" forKey:@"type"];
[media setObject:serverLink forKey:@"href"];
[media setObject:imageSrc forKey:@"src"];
[dictionary setObject:[NSArray arrayWithObject:media] forKey:@"media"];
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = @"Share with All";
dialog.attachment = [dictionary JSONFragment];
[dialog show];
其中JSONFragment方法只是将附件转换为等效的JSON格式
- (NSString *)JSONFragment {
SBJsonWriter *jsonWriter = [SBJsonWriter new];
NSString *json = [jsonWriter stringWithFragment:self];
if (!json)
NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]);
[jsonWriter release];
return json;
}
我希望这会对你有所帮助。