I'm trying to post to the user's feed something like this (it initially shows only one image but when you click "show more" you see all five images)
My code looks like this :
NSMutableArray *properties = [[NSMutableArray alloc] initWithCapacity:5];
NSMutableArray *media = [[NSMutableArray alloc] initWithCapacity:5];
for (MyObject *object in self.myObjects) {
[properties addObject:[NSDictionary dictionaryWithObjectsAndKeys:object.name,@"text",
object.link,@"href", nil]];
NSString *imageUrlString = object.url.absoluteString;
[media addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"image",@"type",
imageUrlString,@"src",
object.link,@"href", nil]];
}
NSData *propertyData = [NSJSONSerialization dataWithJSONObject:properties
options:NSJSONWritingPrettyPrinted
error:nil];
NSString *propertiesString = [[NSString alloc] initWithData:propertyData
encoding:NSUTF8StringEncoding];
NSData *mediaData = [NSJSONSerialization dataWithJSONObject:media
options:NSJSONWritingPrettyPrinted
error:nil];
NSString *mediaString = [[NSString alloc] initWithData:mediaData
encoding:NSUTF8StringEncoding];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:myAppID, @"app_id",
link, @"link",
name, @"name",
caption, @"caption",
propertiesString, @"properties",
mediaString, @"media",
description, @"description", nil];
[FBRequestConnection startWithGraphPath:@"me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:completionHandler];
This only posts one image but I need to post all 5 of them.
EDIT : We are already posting 5 images in one post through janrain engage library so it is doable!
You will need to use the Facebook Connect API directly: the iOS SDK does not expose this kind of functionality.
You should have a look at the Publishing section of the Graph Photo API which suggests this URL to upload an image (don't forget to ask for the publish_stream credential):
POST https://graph.facebook.com/USER_ID/photos
message=[optional description]
source=[the image's data]
place=[optional image's location]
With the iOS Facebook Connect SDK that would give us this call, given you have a Facebook instance called facebook and a UIImage instance called image:
[facebook requestWithMethodName:@"/USER_ID/photos"
andParams:[NSDictionary dictionaryWithObjectsAndKeys:
UIImageJPEGRepresentation(image, 0.7), @"source",
@"My puppy is so cute!!!", @"message",
nil]
andHttpMethod:@"POST"
andDelegate:self];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With