开发者

How to post a message with attachment in Facebook?

开发者 https://www.devze.com 2023-02-08 02:27 出处:网络
I am trying to post a string message on Facebook, but it only posts message type by use开发者_高级运维r not the attachment string. How can I do it ?

I am trying to post a string message on Facebook, but it only posts message type by use开发者_高级运维r 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];

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消