17

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)

Post with 5 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!

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
Moxy
  • 4,162
  • 2
  • 30
  • 49

5 Answers5

1

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];
nivritgupta
  • 1,966
  • 2
  • 20
  • 38
0

ok new idea; how about you send all five of them in a loop, but you keep the status-text and everything else the same. Isn't is possible that facebook then combines them into 1 post?

Bob de Graaf
  • 2,630
  • 1
  • 25
  • 43
  • I need them to be clickable with different urls on Facebook – Moxy Sep 20 '12 at 08:42
  • 1
    ah ok, that's why you can't combine them. hmm I'll try to look into it – Bob de Graaf Sep 20 '12 at 08:42
  • ok new idea; how about you send all five of them in a loop, but you keep the status-text and everything else the same. Isn't is possible that facebook then combines them into 1 post? – Bob de Graaf Sep 20 '12 at 09:02
  • I also found something that it's possible using a batch request: https://developers.facebook.com/docs/reference/api/batch/ – Bob de Graaf Sep 20 '12 at 09:04
  • but I think that posting two times a post with same elements only results in two different graph objects with the same values. It's like posting "Hello everyone!" two times, Facebook will show both! no? – Moxy Sep 20 '12 at 09:14
  • I'm not sure, facebook might combine them, why don't you give it a try and see if it works? – Bob de Graaf Sep 20 '12 at 09:16
  • I'm finishing the last details of my release right now. I'll try it tonight - if I survive - and if the bounty ends, I'll restart a new one ;) – Moxy Sep 20 '12 at 09:22
  • I couldn't do it yesterday... I tried it right now and it didn't work. it created two distinct graph objects on my timeline. I'll start another bounty. Thanks for trying! – Moxy Sep 21 '12 at 14:47
0

Facebook did away with multiple pictures in a post a while ago. When you were able to do it, people were creating "banners" that consisted of multiple pictures side by side. Now only 1 pictured is displayed for any wall post.

You can post more pictures, but they won't be sure by default. Facebook will add a "more" link, although they may have done away with that also.

Source: How to publish a wall post with 2 pictures

So you won't be able to feed pots with multiple images. Better way is to combine 5 images in one image.

Community
  • 1
  • 1
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
  • It is actually possible right now since we can generate it through Engage library (we don't know how they do it). But we're migrating to Facebook iOS SDK so I need a way to do it. – Moxy Sep 25 '12 at 13:38
  • Facebook library doesn't allows it now. See how Engage library is doing this. May be they are making one image from 5 images. But I have used this library. So I don't know much about it. – Somnath Muluk Sep 25 '12 at 14:03
  • Each image in that post is clickable and have a different url so it's not one image. They are 5! Engage provide a different API so I can't know how they achieve it. – Moxy Sep 25 '12 at 19:49
0

You can upload multiple images in an Open Graph action, as described here: https://developers.facebook.com/docs/opengraph/usergeneratedphotos/

Sample code from there:

https://graph.facebook.com/me/nyccookbook:cook?
  recipe=http://www.yourdomain.com/pizza.html&
  image[0][url]=http://www.yourdomain.com/images/my_camera_pizza_pic.jpg&
  image[0][user_generated]=true&
  image[1][url]=http://www.yourdomain.com/images/my_camera_soda_pic_2.jpg&
  image[1][user_generated]=true&
  access_token=YOUR_ACCESS_TOKEN
James Pearce
  • 2,332
  • 15
  • 14
  • This is for actions not for posts. – Moxy Sep 27 '12 at 08:09
  • Correct! Though Open Graph is a good long-term approach to doing this in increasingly configurable ways. – James Pearce Sep 27 '12 at 20:28
  • We already have different actions implemented but we have that one case in which we need a simple feed post with different action. And since we use to have Engage (we still use it on web site) that did it, we want to do it using the sdk. – Moxy Sep 27 '12 at 20:48
  • Got it. Have you had a chance to look at (and synthesize) the API call that Engage makes out the back? – James Pearce Sep 28 '12 at 00:12
0

I think batch requests are what you're looking for.

From this link:

If your application needs the ability to access significant amounts of data in a single go - or you need to make changes to several objects at once, it is often more efficient batch your queries rather than make multiple individual HTTP requests.

To enable this, the Graph API supports Batching. Batching allows you to pass instructions for several operations in a single HTTP request. You can also specify dependencies between related operations (described in a section below). Facebook will process each of your independent operations in parallel and will process your dependent operations sequentially. Once all operations have been completed, a consolidated response will be passed back to you and the HTTP connection will be closed.

...

Uploading binary data

Binary data can be specified as part of the multipart/mime portion of the batch API request. The batch Graph API allows uploading multiple binary items as part of a batch call. In order to do this, you need to add all the binary items as multipart/mime attachments to your request, and need each operation to reference its binary items using the "attached_files" property in the operation. The "attached_files" property can take a comma separated list of attachment names in its value.

Here's a link to a tutorial for creating batch requests using the iOS sdk.

Community
  • 1
  • 1
jhoanna
  • 1,797
  • 25
  • 25