简体   繁体   中英

How to post image to facebook wall with graph api

I want tp post some text with image on facebook wall.I have this code from graph api which does that but i want to post my image from bundle and not from a link as this api does.Can anyone tell me how to post your own image rather then the link "[variables setObject:@"http://bit.ly/bFTnqd" forKey:@"link"];" on facebook wall.

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...");

You covert Image into data and add that as another parameter (Data value for key "data") in the Dictionary.I have given sample here

[variables setObject:imageData forKey:@"data"];

Other Change

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);

Following code should work to solve your problem...

    FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
    dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Photo uploaded.\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"\",\"href\":\"%@/\"}]}",PhotoSourceURL];
    [dialog show];

Let me know, is it working for you or not...

Edit:

Try this one...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM