如何在Facebook中发布带有附件的消息? [英] How to post a message with attachment in Facebook?

查看:106
本文介绍了如何在Facebook中发布带有附件的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Facebook上发布字符串消息,但是它仅按用户发布消息类型,而不按附件字符串发布消息类型.我该怎么办?

I am trying to post a string message on Facebook, but it only posts message type by user not the attachment string. How can I do it ?

- (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];

}

推荐答案

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格式

Where JSONFragment Method simply converts the attachment into equivalent JSON format

- (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;
}

我希望这会对您有所帮助.

I hope this will help you.

这篇关于如何在Facebook中发布带有附件的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆