This article is the final part of a three-part series about how to use Facebooks’s new Graph API in your iPhone app.
In the first part of the series, we covered how to authenticate the user using the Graph API.
In the second part of the series, we covered how to get information from Facebook using the Graph API, in particular the user’s profile.
In this article, we’ll cover how to post to the user’s wall, how to upload a photo to their photo album, and even how to add a “like” button to your Facebook fan page.
So let’s rate some babe, dudes… and maybe a puppy or two!
Posting the Photo
When the user clicks the Rate button, we want our app to upload the photo to Facebook along with a little message that says if the user thought it was hot or not.
So replace rateTapped with the following:
- (void)rateTapped:(id)sender { NSString *likeString; NSString *filePath = nil; if (_imageView.image == [UIImage imageNamed:@"angelina.jpg"]) { filePath = [[NSBundle mainBundle] pathForResource:@"angelina" ofType:@"jpg"]; likeString = @"babe"; } else if (_imageView.image == [UIImage imageNamed:@"depp.jpg"]) { filePath = [[NSBundle mainBundle] pathForResource:@"depp" ofType:@"jpg"]; likeString = @"dude"; } else if (_imageView.image == [UIImage imageNamed:@"maltese.jpg"]) { filePath = [[NSBundle mainBundle] pathForResource:@"maltese" ofType:@"jpg"]; likeString = @"puppy"; } if (filePath == nil) return; NSString *adjectiveString; if (_segControl.selectedSegmentIndex == 0) { adjectiveString = @"cute"; } else { adjectiveString = @"ugly"; } NSString *message = [NSString stringWithFormat:@"I think this is a %@ %@!", adjectiveString, likeString]; NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"]; ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; [request addFile:filePath forKey:@"file"]; [request setPostValue:message forKey:@"message"]; [request setPostValue:_accessToken forKey:@"access_token"]; [request setDidFinishSelector:@selector(sendToPhotosFinished:)]; [request setDelegate:self]; [request startAsynchronous]; } |
In the beginning, we check what image the user is looking at, and get the path of the image to send appropriately. We also get a string describing the image that we’ll use a bit later.
Next, we create a string that we’ll use as a caption for the photo, taking whether the segmented control is on “hot” or “not” and the image currently shown.
The real meat of the work is again done with ASIHTTPRequest – or wait a minute, ASIFormDataRequest. ASIFormDataRequest is a subclass of ASIHTTPRequest, that makes it easy to POST data to a web server – which is exactly what we need to do to upload a photo.
To see what types of things you can post to Facebook, check out the Graph API reference, in particular the “Publishing to Facebook” section. There we can see that when uploading a photo, we can include just two things: the photo itself and the caption (called “message” here).
ASIFormDataRequest has many ways to include raw data in a form request. We’re using the addFile method to include the image that way. If you need to include data from NSData or another method, check out the handy ASIHTTPRequest docs to see other ways to include your data.
So, after we set the image, message, and access token, we fire off the request and set a delegate to be called back when it’s done. And in that, let’s get some info on the photo!
Getting Object Information
After we post a new object to Facebook, Facebook returns to us the ID. We can use that ID to query the object, and get other potentially useful information – like the link to the photo on Facebook in this case!
So let’s give that a shot. Add this method next:
- (void)sendToPhotosFinished:(ASIHTTPRequest *)request { // Use when fetching text data NSString *responseString = [request responseString]; NSMutableDictionary *responseJSON = [responseString JSONValue]; NSString *photoId = [responseJSON objectForKey:@"id"]; NSLog(@"Photo id is: %@", photoId); NSString *urlString = [NSString stringWithFormat: @"https://graph.facebook.com/%@?access_token=%@", photoId, [_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSURL *url = [NSURL URLWithString:urlString]; ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url]; [newRequest setDidFinishSelector:@selector(getFacebookPhotoFinished:)]; [newRequest setDelegate:self]; [newRequest startAsynchronous]; } |
Here we pull out the photo ID after a sucessful upload. Based on that, we send out another request to get the properties of that object with the URL https://graph.facebook.com/objectID. IDs are unique across all types of objects, so this would work for any object type.
We send out the request the exact same way we did when we queried for the user’s profile in the last tutorial. When it’s done, we’ll get a callback on getFacebookPhotoFinished, so let’s add that next!
Posting to the User’s Wall
Once we get the photo info, we can pull out the link to the photo and potentially do something useful with it. My original idea was to include the image in a post on the user’s wall saying what he rated the photo, but apparantly Facebook doesn’t allow you to link to photos on its network on wall posts for whatever reason.
Update: Strike that! Mic Pringle from the comments section pointed out that Facebook now allows you to post links to pictures in its stream on wall posts, so we’re good to go!
So add this to the file next:
- (void)getFacebookPhotoFinished:(ASIHTTPRequest *)request { NSString *responseString = [request responseString]; NSLog(@"Got Facebook Photo: %@", responseString); NSMutableDictionary *responseJSON = [responseString JSONValue]; NSString *link = [responseJSON objectForKey:@"link"]; if (link == nil) return; NSLog(@"Link to photo: %@", link); NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"]; ASIFormDataRequest *newRequest = [ASIFormDataRequest requestWithURL:url]; [newRequest setPostValue:@"I'm learning how to post to Facebook from an iPhone app!" forKey:@"message"]; [newRequest setPostValue:@"Check out the tutorial!" forKey:@"name"]; [newRequest setPostValue:@"This tutorial shows you how to post to Facebook using the new Open Graph API." forKey:@"caption"]; [newRequest setPostValue:@"From Ray Wenderlich's blog - an blog about iPhone and iOS development." forKey:@"description"]; [newRequest setPostValue:@"http://www.raywenderlich.com" forKey:@"link"]; [newRequest setPostValue:link forKey:@"picture"]; [newRequest setPostValue:_accessToken forKey:@"access_token"]; [newRequest setDidFinishSelector:@selector(postToWallFinished:)]; [newRequest setDelegate:self]; [newRequest startAsynchronous]; } |
If you’ve done the Facebook Connect tutorial or used Facebook Connect before, the above should look pretty similar. We’re setting the same kinds of values we normally would on a wall post here – message, name, caption, etc. – except it is a lot nicer to use this way I think.
Now that you’ve seen how to upload photos, you’ll see that there’s really nothing different about making wall posts! You’re just setting different parameters, which you can find out about in the Graph API reference.
One last callback to add:
- (void)postToWallFinished:(ASIHTTPRequest *)request { NSString *responseString = [request responseString]; NSMutableDictionary *responseJSON = [responseString JSONValue]; NSString *postId = [responseJSON objectForKey:@"id"]; NSLog(@"Post id is: %@", postId); UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"Sucessfully posted to photos & wall!" message:@"Check out your Facebook to see!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease]; [av show]; } |
We just pop up a dialog here to let the user know when we’re done.
That’s it! Run the project and you shoudl see a success message when you click Rate:
And then a post (or two, one is automatically made the first time you upload a new photo album I think) to your wall:
Adding a Like Button to your Facebook Fan Page
One last thing to discuss. These days as app developers, a lot of us are trying to start up Facebook Fan Pages, so maybe we want to add a like button to our apps!
After learning about the Graph API you might start looking for some kind of ability to POST to the user’s likes somewhere. That would make a lot of sense, wouldn’t it? But unfortunately, Facebook has decided not to allow custom like buttons.
However, luckily that doesn’t mean we can’t use like buttons in our apps – we just have to use Facebook’s like button. And to do that, we have to embed it in a webview in our app. And we have one standing by just for that!
All you have to do is visit Facebook’s Like Box Maker and fill out the values to create the Like button for your Facebook Fan page the way you like it. For the space we’ve given it in this tutorial, you should set connections to 0 and stream and header off.
Then add the following method above getFacebookProfile, replacing the likeButtonIframe with your own likebox code (don’t forget to escape out the quotes):
- (void)showLikeButton { NSString *likeButtonIframe = @"<iframe src="http://www.facebook.com/plugins/likebox.php?id=122723294429312&width=292&connections=0&stream=false&header=false&height=62" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:282px; height:62px;" allowTransparency="true"></iframe>"; NSString *likeButtonHtml = [NSString stringWithFormat:@"<HTML><BODY>%@</BODY></HTML>", likeButtonIframe]; [_webView loadHTMLString:likeButtonHtml baseURL:[NSURL URLWithString:@""]]; } |
Then just add this at the end of accessTokenFound:
[self showLikeButton]; |
And if all works well, your like button should appear in the window!
Where To Go From Here?
Here is a sample project with all of the code we’ve developed in this tutorial series.
At this point, you should be ready to use Facebook’s Graph API for whatever you need – without having to wait for an update to Facebook Connect! I’d love to hear what you guys plan on using it for.
And while we’re on the topic of Facebook, if you enjoyed this tutorial I’d love it if you would “like” my own Facebook fan page! Just click the link below (or in the app)! :]
Category: iPhone










Once I spent so much time on facebook api. It was really sucks before. But i haven’t tried new graph api. Thx for your tutorial, i will give it a try soon~~ Keep on with it pls~~~
Hi Ray,
thank you for the tuto. I have already followed the first part of your tuto to enable my users to connect to their facebook account. It works well. But I am really surprized by the fact that using this new API there is more work to do : with FB Connect we had already dedicated facebook button to launch the login page. With Graph API we have to design the login page and to make our own fb button. Weird …
I would appreciate the same kind of tuto for twitter connection as I plan to also include it in my app :)
Thanks for the great job !
by the way, for people wanting to use common FB design button images you can get them here :
http://wiki.developers.facebook.com/index.php/Facebook_Connect_Login_Buttons
another question Ray :
when I use your code sample, if I connect to FB the I quit the iPhone app and I relaunch it I have to login again. How can we keep the user logged as it was the case using FBConnect ? Because as it is it is not really usable in an app and I don’t really know how to fix it.
Thanks ;)
I love your posts because they’re pratical, well explained and real! Well done man!!
Hi Ray, great post as usual.
Does the access token persist across app startups? Basically, can I persist the access token in the device and not ask the user to login every time?
@Jackie, @amok: Thanks!
@olinsha, @tim: Regarding saving login information: Actually the current session is saved as a cookie in the web browser, but for some reason it takes a couple seconds for the web browser to persist the cookies to the disk… if you log in, wait a bit, then relaunch your app it should stay logged in. Not sure if there’s a way to make it save the cookies on demand. Also I think there is a way to request a permission to log in on behalf of a user, but I haven’t played with that yet.
@olinsha: Yeah they haven’t written a library for the Graph API yet, so we’re left with writing our own buttons, etc. Thanks for the link to the images!
Thanks for the idea on the Twitter API integration, somebody else was asking for that too, put a star next to it on my idea list of potential future blog posts…
Actually I found that one of the permissions you can ask for gives you an infinite access_token which you can persist.
@Tim: Cool, yeah I thought there was something that did that. Which permission was that?
I am also interested by the answer Tim ;)
Ok I think I have finally found the answer :
http://developers.facebook.com/docs/authentication/permissions
the extended permission allowing us to keep the user connected even when we close the application is offline_access
That’s such a great article as usual. I really impressed about your tutorial’s quality. I’m finding a way to integrate social media as leaderboard on my coming games…
@olinsha: Very cool, thanks for updating us!
@Thang: Thanks! Very cool regarding your leaderboard!
Thang,
if you really want to have cool mixing between social network and games you can also check OpenFeint. It’s a very powerful and easy to use framework.
@olinsha: thanks so much for the suggestion. I have been looking for OpenFeint. There’s many choices that would make me confused :)
Great Tutorials! They have helped me a lot. I am having a little trouble downloading an image and storing it in a UIImage. i.e. …/me/picture. Any ideas?
@Wyeth: I’m not sure what part in particular you’re having trouble with, but the general flow would be:
* Download the image from the web using NSURLRequest or ASIHTTPRequest, getting an NSData as a result
* Call [UIImage imageWithData:xxx] to get a UIImage representation that you can use in your app…
* Later to save it to disk, either use the NSData you already have, or call UIImagePNGRepresentation() to turn it into an NSData again
* Then you can call [data writeToFile:xxx atomically:YES] to write it out to disk.
Hope this helps!
Sorry I was a little vague in my question. I actually figured out where I was going wrong. I needed to use responseData instead of responseString. I also had a little trouble figuring out how to populate a tableViewCell with the image until I realized I needed to make a custom tableViewCell and make the request inside of it. I was able to make a really nice friend selector in an indexed table view with a search bar just like the iPhone facebook app. Thanks again your tutorials are a great help.
Hi Ray, thanks for all the very helpful info!
One note: the sample project you linked to (FBFun) is missing all the ASI files (16 .h and .m files from ASIAuthenticationDialog.h to ASIProgressDelegate.h). I’d love to check out your sample, so if you get a chance to add these and repackage the sample project, that would be fantastic. Thanks again!!
Ran – You can download and add to the project the ASI by yourself, it’s pretty straightforward. Here is the link
http://allseeing-i.com/ASIHTTPRequest/
@Wyeth: Ok, great!
@Ran: Whoops! Sorry about that! Have updated the sample project to contain the files. @amok is right it’s easy to add them yourself, but usually I like to have the sample projects be as easy to run/use as possible…
Thanks Ray! I got my app working the way I needed it to thanks to your code examples, even without the ASI, but now your project is more complete for future visitors. =) I appreciate it!
Ray;
I am getting errors with your code and with mine.
2010-08-22 13:09:23.703 FBFun[60895:207] Photo id is: 1413580975899
2010-08-22 13:09:23.808 FBFun[60895:207] Got Facebook Photo: false
2010-08-22 13:09:23.810 FBFun[60895:207] -JSONValue failed. Error trace is: (
“Error Domain=org.brautaset.JSON.ErrorDomain Code=4 \”Valid fragment, but not JSON\” UserInfo=0x5d2cb20 {NSLocalizedDescription=Valid fragment, but not JSON}”
)
The picture does upload. I can make it post to wall or post picture (with) this error but not both.
Do you have any ideas?
-Jim
@Jim: Hm… I just tried the sample project here and it posted OK for me, so maybe there’s something different about your Facebook account or something? From the error trace it looks like the responseString from trying to get the uploaded photo isn’t the JSON for the photo like expected (it’s saying false as if there was a failure). I suspect that the code just isn’t dealing with the repercussions of the “get photo” call failing, so the JSON error is just a cascading error from that.
I’m not sure offhand why the call to get the photo by ID would be failing (from sendToPhotosFinished) – if you figure out any more info let me know!
Ray;
On last thing. It works fine if the following is commented out. Obviously not what you intended as there is no way to make sure photo posted (except do get valid photo id)
NSString *responseString = [request responseString];
DEBUGLOG(@”%s : Got Facebook Photo: %@”, __PRETTY_FUNCTION__, responseString);
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *link = [responseJSON objectForKey:@"link"];
if (link == nil)
{
return;
}
DEBUGLOG(@”%s : Link to photo: %@”, __PRETTY_FUNCTION__, link);
-Jim
Thanks Again Ray for the great service you do us all. I added code to check for a valid photo id instead of trying to check the link. Must be my permissions like you said. Really weird.
-Jim
Thanks very much Ray for the wonderful tutorials!
I’m having the same problem as Jim – have been trying to figure it out for a few hours, but no luck. Jim, if you do discover the cause, please let me know. Am hugely relieved to find that someone else has been seeing the same strangeness (the success callback is called, there’s no error message, but the response is just “false”).
Hi Laura
I just make sure I got a good Photo ID. I changed Ray’s code to check that and not fail if I can’t get link. I still have no idea why it is happening. I even went and played with my facebook privacy settings. :-(
-Jim
-(void)sendToPhotosFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
NSMutableDictionary *responseJSON = [responseString JSONValue];
if (!responseJSON)
{
UIAlertView *av = [[[UIAlertView alloc]
initWithTitle:@”Photo Posting Error.”
message:@”Error Posting character to Facebook.”
delegate:nil
cancelButtonTitle:@”Bummer!”
otherButtonTitles:nil] autorelease];
[av show];
[self showModal];
return;
}
NSString *photoId = [responseJSON objectForKey:@"id"];
DEBUGLOG(@”%s :: Photo id is: %@”, __PRETTY_FUNCTION__, photoId);
NSString *urlString = [NSString stringWithFormat:
@"https://graph.facebook.com/%@?access_token=%@",
photoId, [accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
DEBUGLOG(@”%s : url: %@”, __PRETTY_FUNCTION__, urlString);
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url];
[newRequest setDidFinishSelector:@selector(getFacebookPhotoFinished:)];
[newRequest setDelegate:self];
[newRequest startAsynchronous];
}
-(void)getFacebookPhotoFinished:(ASIHTTPRequest *)request
{
NSString *responseString = [request responseString];
DEBUGLOG(@”%s : Got Facebook Photo: ‘%@’”, __PRETTY_FUNCTION__, responseString);
if (responseString != nil &&
([responseString rangeOfString:@"false"].location) == NSNotFound)
{
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *link = [responseJSON objectForKey:@"link"];
if (link != nil)
{
DEBUGLOG(@”%s : Link to photo: %@”, __PRETTY_FUNCTION__, link);
}
}
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];
ASIFormDataRequest *newRequest = [ASIFormDataRequest requestWithURL:url];
[newRequest setPostValue:kFacebookMessage forKey:@"message"];
[newRequest setPostValue:kFacebookName forKey:@"name"];
[newRequest setPostValue:kFacebookCaption forKey:@"caption"];
[newRequest setPostValue:kFacebookDescription forKey:@"description"];
[newRequest setPostValue:kFacebookLink forKey:@"link"];
[newRequest setPostValue:kFacebookLogo forKey:@"picture"];
[newRequest setPostValue:accessToken forKey:@"access_token"];
[newRequest setDidFinishSelector:@selector(postToWallFinished:)];
[newRequest setDelegate:self];
[newRequest startAsynchronous];
}
@Jim: Thanks for sharing your solution!
Thanks Jim!
I finally figured it out.
NSString *permissions = @”publish_stream”;
This doesn’t seem to give you permissions to get info about their photos. You have to request:
NSString *permissions = @”publish_stream,user_photos”;
The permissions seem to be persisted inside Facebook for your app, so if the user ever grants you those permissions, you won’t have to request them again, even if they delete your app and reinstall, log in and out, whatever. I’m guessing that others doing the tutorial must already have requested those permissions at some point, so they didn’t get the error.
Now if I can just figure out how to tag the images as I send them …
Awesome Laura! Thank You!!
No I need to figure out how to let it be the profile picture :)
-jim
@Laura: Wow awesome Laura, I’m glad you tracked down this mystery! Thanks for posting the solution as well.
this is a great tutorial
thanks very much.
but i got a problem
i set
NSString *permissions = @”publish_stream”;
to
NSString *permissions = @”publish_stream,user_photos”;
after that i can’t login.
it just stop at “connecting to Facebook…”
any idea
@purple: Not sure off the top of my head, maybe try the Facebook SDK forums:
http://forum.developers.facebook.net/
@Ray
It now seems as though Facebook have reversed the decision to not allow uploaded photos into the stream, so would you be at all prepared to do a small update to this post to show how to achieve this (that was your original plan afterall)?
@Mic: Thanks for the heads up! I’ve updated the tutorial and sample code with this.
@Ray: Brilliant! Thanks so much for taking the time to do this.
@Mic: Do you have a link to an announcement from FB about reversing their decision? I can’t seem to find anything about this, and I’m still seeing complaints from devs as recent as today about not being allowed to do this. I’m a total newbie when it comes to FB apps, and I have a client who wants to know what’s possible with regard to uploading images to FB from an iPhone app, so I’m trying to figure out the current state of things.
@Ray: HUGE thanks for taking the time to write all of this up! This really helped me get up to speed on the current state of FaceBook’s Graph API.
Thanks!
Nice tutorial, thanks.
I’ve been trying to figure out how to post a message with dynamic data (like a game posting a highscore to the FB feed) for 3 weeks and I think the code for the message block with the “I’m learning how to post to Facebook from an iPhone app!” text finally has an example I can learn from.
The iOS graph api documentation and tutorials arent very prevalent on the web yet.
@ChrisL
Whilst I no longer have the link to the forum post where I found out this information, the notice that once appeared in the Facebook API docs about not being able to link to images on the FBCDN domain has been removed.
I’m also assuming @Ray tested the feature before updating his blog post, so he must have also found no issues?
Have you updated to the latest SDK version?
@Mic: Thanks for the clarification. I haven’t actually tried implementing the sharing functionality yet, just trying to get a sense of what’s possible/allowed so I can give my client accurate information. I don’t want to implement something that has a high likelihood of breaking down the line without at least warning my client of the possibility and letting them decide how to proceed. Thanks again!
@Mic: Thanks for helping out ChrisL!
hey Ray,
Do you have any idea how to integrate Facebook chat client in iPhone application.
-Shweta
Hi Ray,
I made a similar code, not directly with ASIFormDataRequest but with [facebook requestWithGraphPath ...] api and I fill requested parameters -basically should be the same as your code.
Everything works, uploading photo, retrieving photo properties, but the final step does not work. Whenever I include “picture” parameter with link I get response:
Error Domain=facebookErrDomain Code=10000 UserInfo=0x5c722b0 “Operation could not be completed. (facebookErrDomain error 10000.)”
If I comment picture parameter, post appears in the feed but without picture. I also tried to post link as “link” parameter – it works, there is link but again no image.
I tried to post it also as “image” parameter but no success.
Are you sure that Facebook has allowed link to their own photos. Here it look as it is not possible. I will try just for test if it works if I link from my website.
Update on my last comment.
If I provide a link for @”picture” parameter from my website – not from Facebook – the image is included in feed post.
I also tried to link directly to one of jpg source links inside “images” response parameter … it is also rejected.
Hm, what to do, I really need picture to be included from facebook server not any other.
@Ray: I’ve finally gotten around to testing this, and despite Mic’s info, this doesn’t seem to be working for me. Can you verify that posting to the wall was working at the time you updated your post to include the code to post to the wall? When I run your code, the image uploads correctly, but the wall post fails with a response “(#100) FBCDN image is not allowed in stream”.
Hi Ray,
Don’t know why your like button is not working, it shows “You liked this.”, then I go to your Facebook Razeware page with the same account, but I did not like the page?
Thanks for the tutorial! :-D
@Shewta: Integrating with Facebook chat is a completely different beast – see this guide for more details:
http://developers.facebook.com/docs/chat
@Matej, @ChrisL: I just tried out the sample project again to make sure it works OK for me, and it seems to upload fine to my account. If you’re having troubles, I’d recommend checking at the Facebook developers forum here:
http://forum.developers.facebook.net/
@Edward: Hm weird! Just copied/pasted the code to add the widget from the Facebook site. But with Facebook who knows lol. Glad you liked the tut!
Thanks for following up, Ray. Yes, I’ve been spending way more time that I would have liked on FB’s forums these past few weeks. :) Right now, uploading a photo now seems to automatically post it to the stream, which is highly desirable but something that definitely hasn’t been working consistently for me over the past month. I haven’t made any changes on my end, so it seems to just come and go from time to time. Fingers crossed that it will stay this way for a while — thanks again!
This is very helpful post! Thank you very much.
@ChrisL: Wow, sounds like a pain. I’ve heard a lot of nightmare stories from Facebook devs having troubles like that where things work one day but not the next. Hope it works out for you!
@Jirapong: Thanks! And cool Gravatar btw :]
Hi Ray Wenderlich,
Thanks for posting the tutorials, it was very helpful for us to integrate new FBConnect Graph API’s.
I am also trying the checkin feature, For which we need to pass the PAGE_ID. Do you have any idea from how we can fetch the PAGE_ID.
Thanks in advance,
Vikas C.G
@vikas: Sorry no idea, haven’t played around with that myself. Best of luck though!
@Purple: I have had the same problem. Every time I change the permissions I need to delete the build in xcode and on the iPhone simulator. Then re-run and it always works fine
@Ray: Awesome tutorial – thank you SO much :-) Is there a way to get an iframe to appear on the users iphone before they publish the wall post (so they can preview it before publishing)?
Another Great Tutorial!
Any chance you could show how to post a link with meta data so users could share app data using facebook?
I can do this by emailing a link but was wondering if Facebook would allow a non-http: link with meta data to be published as a link?
Thanks
Greg
Hi Ray,
Its really great post. But i am having some problem with like button.
When i click on like button it shows “You liked this.”, then I go to your Facebook Razeware page with the same account, but I did not like the page?
Actually in my application i want to like a URL. Can you please suggest me how to do that.
Thanks a lot
Hi Ray:
Thanks for all the projects. They are really very helpful and great a starter to work with FB apps. I wanted to port all the contacts name, phone and email addresses from FB contacts, is it possible? Can I connect to FB just to sync my address book?
Thanks dude!
@Charlie: Back when I was using Facebook Connect’s SDK they had an automated mechanism to do that, maybe check that out?
@Greg: Hm, interesting question! I’d say just replace the URL in this example with the URL you want to try, and just see if it works.
@Avinash: Somebody else said it had that problem too… don’t really know why, I’m literally just pasting the code from Facebook’s site!
Regarding liking a URL, is that even possible? Looking at the Graph API overview it appears you can like a post or profile, but I don’t see a URL…
@Rahul: You can get the user’s friends list with the Graph API, then look up the info for each user – some will have email addresses associated, some won’t.
any solution for the “Like” button going AWOL. ??
@BK: Not AFAIK…
@Ray: Are you sure that the like button in the UIWebView works as expected? AFAIK the FBConnect doesnt share the cookies with the UIWebView – so it cannot work.
I works only if you have been logged into facebook before, in the same or any other UIWebView of this application.
First – a BIG thank you Ray
The examples are well explained and lucid
The code is complete and not half baked and the examples actually run !
A big thank you
I am limiting myself to the piece in your tutorial regarding extended permissions
My requirement is to get the extended permission for email
Using your example things work – but I need a WebView
I would much rather use the FBConnect style where a button is provided and the screen pops up
So question is – can I get extended permissions for email using FBConnect ?
Is there a way that the code in your example can be embedded in “didLogin” / “didLoad” to ensure we get the permissions ?
I have been struggling for days to get the extended permissions to work using FBConnect
You do indicate that FBConnect supports extended permissions – so any help is appreciated
The frustrating thing about Facebook forums is that many people have asked this question and nobody responds
Last but not the least – you are a life saver with clear concise and tpo the point examples with no fluff
Thanks,
satish
sorry I meant I do NOT want to use the webview
I have also posted this question here:http://forum.developers.facebook.net/viewtopic.php?pid=293225#p293225
and have taken the liberty to mention your great example
thanks
@M:ke: I thought it was working when I tested it, but who knows I could be wrong!
@satish: Thanks, glad you liked the tutorial! Unfortunately I don’t have an example of using extended permissions with FBConnect offhand, but if I ever do write another Facebook tutorial about how to use the (now updated) SDK, I will include an example of how to do that.
Hi Ray,
Thanks for this great tutorial. Your tutorials are always worth appreciation. I just wanted to ask that can both “loginButtonTapped” and “rateTapped” events be implemented on a single button click?What should be done to do so?
It would be great if you could help me out!!
Thanks!!
Hi Ray,
Million thanks for your GREAT tutorial!!
Also thanks to Jim, Laura and Charlie above to get the getFacebookPhotoFinished: works.
However, I’m facing another problem now is that using
[newRequest setPostValue:link forKey:@"picture"];
will give me a “Post id is: [null]“. But using
[newRequest setPostValue:@"http://www.raywenderlich.com/wp-content/themes/raywenderlich/images/logo.jpg" forKey:@"picture"];
will have no problem. Any hint on that?
@Parth: You have emailed me about this as well, and I have responded.
@Anthony: Might be Facebook giving you problems about linking to an image hosted on their servers on a wall post, I know it’s been on/off whether they allow that or not. Try hosting your file on your own web server and see if that works?
Hey, I posted here a few weeks ago about things not working. It turned out to just be an error on my part and a bug on Facebook’s end that has been sorted out now.
I do have one more thing though, this sample works fine now, except for one problem. The pop up notifications, successfully posted to the wall, etc, you have included in the tutorial don’t actually pop up when I run it. I’m sure I’ll tear into implementing your tutorial in my own application soon so maybe I’ll find out what the deal is then, but I just wanted to give you a heads up.
Also, if it’s supposed to switch between the different images when you rate one, it’s not.
Hei!
First of all, thank you for all these awesome tuts!
I’m also developing and iPhone App and one question came out when I had to register the Facebook App. I created an application (just clicked the “create button”) and I didn’t do anything more than copy the application ID and use it to connect my iPhone App with Facebook, but, do I need to have a webpage and use it in my Facebook application? If I don’t do it, can Facebook remove my app?
Thank you in advance, hope you can help me.
@thomas fallon: I think facebook doesn’t allow you to post your facebook pictures. I can only post to the user wall if I don’t fill the “picture” field. (I’m using publish_stream and user_photos permissions and it’s not possible). And in the tutorial you are trying to post the picture, that’s why the notification doesn’t pop up. Hope it helps!