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 ha开发者_Python百科ve 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];
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.
I don't think you have to post a picture. Also, what Facebook is doing is getting Open Graph tags (meta tags in the beginning of web documents just for this purpose). You should be able to simply post a link and a message, and it will "lint"- read the meta tags and post the picture, summary, etc. for that web page.
You may try using Open Graph graph actions instead of share dialogs. It will do more of what you want.http://developers.facebook.com/docs/opengraph/
精彩评论