Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS SDK posting a link & displaying a thumbnail

I've managed to get the Facebook iOS SDK implemented into my project quite nicely with the assistance of the provided FB documentation.

My app's FB integration is quite simple: A Facebook share button, which allows a user to post a link to their FB wall with a user-supplied comment. Nothing earth-shattering or ground breaking.

However, I would like to go one step further. I don't have a thumbnail to display for the link (i.e. my own image URL), but I would like the thumbnail to be automatically selected by Facebook.

Similar to how, from Facebook in a web browser, if you choose to Share a link from CNN.com, Facebook will automatically select thumbnails for the desired page to be shared, AND it even gives you the option to checkbox "no thumbnail".

From the iOS dialog to share the link, I would like the thumbnail to automatically be selected (presumably it's generated from the link that you're trying to share, i.e. FB just grabs images from the page).

Is this possible? Again, I do not want to display "picture" with a supplied image URL in the 'attachment' NSDictionary below because I won't have the image URL. I just want to display a hyperlink and have FB post the link on the user's wall with their comment and have FB supply the thumbnail image (similar to how it would if you posted from a web browser).

Basically the code from Stack Overflow is:

SBJSON *jsonWriter = [[SBJSON new] autorelease];

NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary     
dictionaryWithObjectsAndKeys: @"Always Running", @"text", @"http://itsti.me/", @"href", 
nil], nil];

NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                           @"a long run", @"name",
                           @"The Facebook Running app", @"caption",
                           @"it is fun", @"description",
                           @"http://itsti.me/", @"href", nil];

NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                             @"Share on Facebook",  @"user_message_prompt",
                             actionLinksStr, @"action_links",
                             attachmentStr, @"attachment",
                             nil];

[_facebook dialog:@"stream.publish" andParams:params andDelegate:self];
like image 715
Brian Avatar asked Nov 13 '22 21:11

Brian


1 Answers

A different approach to this would be to call the Graph API instead of using a dialog. So if you make an HTTP POST to https://graph.facebook.com/me/feed and supply the message and link parameters the image should be automatically selected by Facebook. See https://developers.facebook.com/docs/reference/api/user/#links.

You will have to generate the UI to ask the user to enter the message. If that can work for you then this is the way to go.

like image 169
C Abernathy Avatar answered Dec 21 '22 07:12

C Abernathy