27 January 2010

How To Post on Facebook with Your iPhone App

 

Screenshot of a Facebook post from the article's sample iPhone App

Make a post like this from your app!

Integrating Facebook into your app is a great way to let users share content from your app with their friends. For example, if you have an app where users can record their grades, why not add a button to let the users share their final grades with their friends at the end of the semester? It could be fun for the users, and could also let a lot more people know about your app.

The Facebook developers have made it quite easy to integrate Facebook in your iPhone app with a great SDK. This article will show you how to quickly and integrate Facebook into your iPhone app – and it comes with a simple example project to follow along with!

Update: Since writing this article, a new Facebook SDK (using the Graph API) has come out. This article does not cover that – it covers the old Facebook SDK (using the REST API), which is still available and operational at the time of this writing.

There have been several changes to the Facebook SDK since I wrote this article (early this year). I may update this article with the changes at some point, but until then no guarantees are made! :]

Register Your Application With Facebook

The first thing you have to do is to register your app with Facebook. It’s an extremely simple process:

The "Create Application" step in Facebook
  1. Go to the Facebook developers portal, log in, and allow access to the Developer application.
  2. Click the button “Set Up New Application”, give it a name (the name of your application will do), and click “Create Application”.
  3. Now you’ll be at a screen where you can edit the details of the application. You’ll probably want to set the description and logo, but the rest is really optional for now.
  4. Finally, record the values in “API Key” and the “Secret” sections. You’ll need those later!
  5. Update: smaug from the comments section mentioned that he had to set the iPhone application ID in the Advanced tab to the app ID for his app to get it to work – so you may need to set this as well if you have problems!

Add the Facebook iPhone SDK Into Your Project

Next, go to the Facebook iPhone SDK project page and click the “Download Source” button to pull down the latest copy of the SDK. Feel free to look through the project. In particular, the “Connect” sample project is a great demo of some of the most important functionality.

But for the purposes of this article, we’re going to dive straight into things! Adding the SDK into your project is easy:

Directory structure for sample project

Directory structure for sample project

  1. Move the SDK into a known location relative to your project. For example, I have my code in a folder called “Level Me Up”, and I put the SDK folder (which I named “facebook-iphone-sdk”) as a sibling folder.
  2. Open up the src\FBConnect.xcodeproj from the SDK that you downloaded, and your own project as well.
  3. Drag the FBConnect group to your project. When the prompt appears, make sure “Copy items into destination group’s folder” is not clicked.
  4. Go to Project\Edit Project Settings, and scroll down to “Search Paths\Header Search Paths.” Make sure “All Configurations” is sleeted, and add an entry to your search path that points to the src folder in the SDK – I used “../facebook-iphone-sdk/src”.
  5. Test that you have things working correctly, by importing the Facebook SDK headers. Just add “#import “FBConnect/FBConnect.h” to one of your header files and give it a compile to check everything is working!

Logging the User In

To log the user into Facebook, you need to set up a session for the user. Facebook sessions are managed by the FBSession object – and there can only be one session at a time. Therefore, you probably want to declare your FBSession somewhere that is easily accessible by any place in your code that may need to use it. In the sample project, I just have a single view controller, so I put it there, but for larger projects you should use a more central location.

To initialize your session, you need to give it some API keys so Facebook can distinguish between your application and someone else’s. This is often done in the viewDidLoad method where you want to start using Facebook, and there are two methods of doing this:

  • Hard code the API key and secret key into your application, and use the sessionForApplication:secret:delegate: method. This method is the easiest way, but someone motivated could reverse engineer your code and retrieve your secret key, and write an app to pose as your application.
  • The better way is to use the sessionForApplication:getSessionProxy:delegate method and pass a URL to a web server you control. At that URL, you can implement a service that uses Facebook Connect’s PHP API to call facebook.auth.getSession (with a hardcoded key there) and send the results back to the app. This method is higher security because to figure out your key, someone would need to have access to your web server.

Here’s what it looks like with the sessionForApplication:secret:delegate method:

static NSString* kApiKey = @"8fa673a06891cac667e55d690e27ecbb";
static NSString* kApiSecret = @"325a4c580253c7619313baad5712cc2a";
_session = [[FBSession sessionForApplication:kApiKey 
                                      secret:kApiSecret delegate:self] retain];

Next, it’s time to log the user in. The Facebook SDK makes it very easy to display a login dialog:

_loginDialog = [[FBLoginDialog alloc] init];	
[_loginDialog show];

If you’d like to know if and when the user successfully logs in, all you have to do is implement the session:didLogin method in your FBSessionDelegate.

One of the nice things about sessions is they persist to disk automatically. After you set the API keys for your session, you can restore an old session by calling “[_session resume]“. This method will return YES or NO based on whether the session is valid or not, and it will also call session:didLogin on your delegate if the session is valid.

Posting to the User’s Wall

You can post to a user’s wall using the FBSteamDialog class, and a bit of markup. First, here’s an example:

FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = @"Enter your message:";
dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@ got straight A's!\",\"href\":\"http://www.raywenderlich.com/\",\"caption\":\"%@ must have gotten real lucky this time!\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.raywenderlich.com/wp-content/themes/raywenderlich/images/logo.jpg\",\"href\":\"http://www.raywenderlich.com/\"}]}",
	 _facebookName, _facebookName];
dialog.actionLinks = @"[{\"text\":\"Get MyGrades!\",\"href\":\"http://www.raywenderlich.com/\"}]";
[dialog show];

The above will result in a post that looks something like this:

Facebook Post Example

Facebook Post Example

For simple posts, you should be able to tweak this sample pretty easily. If you want to do something more complex, refer to this great Facebook post attachment reference guide for all of the details.

Getting the User’s Facebook Name

If you integrate Facebook into your app, you’re probably going to want to get the user’s Facebook name, so that you can display who they are currently logged in as and let them log out, if nothing else.

The easiest way to do this is to use the same method used in the example provided by the Facebook SDK team – run a query against the Facebook database after a successful login.

NSString* fql = [NSString stringWithFormat:
    @"select uid,name from user where uid == %lld", _session.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];

The results will come back in the request:didLoad method in your FBRequestDelegate:

- (void)request:(FBRequest*)request didLoad:(id)result {
	if ([request.method isEqualToString:@"facebook.fql.query"]) {
		NSArray* users = result;
		NSDictionary* user = [users objectAtIndex:0];
		NSString* name = [user objectForKey:@"name"];
		// Do something with the name!
	}
}

The Sample Project!

That’s all there is to it! So if you haven’t already, take a look at the example iPhone project showing how to make a Facebook post like the above. Feel free to play around (and even use the included API/Secret key) to test things out.

Where to Go From Here?

If you are writing a new app that you want to integrate with Facebook and want to be on the cutting edge, check out the follow-up tutorial series on How To USe Facebook’s New Graph API from your iPhone App. The new API is kind of cool and lets you do some things that you just can’t do with the old API in Facebook Connect.

How have you been using (or planning to use) Facebook in your apps? How has it been working out for you?


Category: iPhone

Tags: , , ,

132 Comments

  1. Kuba (3 comments) says:

    I was just about to start implementing posting to Facebook. Thanks for this post, I will have a look at this!

  2. John (5 comments) says:

    Hey, great site. Thanks for the info on Facebook. I was just thinking about trying to do something similar with an app I’m working on. Can’t wait to read more!

  3. Ray Wenderlich (874 comments) says:

    Glad you guys found it useful, best of luck with your implementations! :]

    And John thanks, your blog looks great too, I just subscribed!

  4. John Zachary (1 comments) says:

    This post saved me some work. Thanks for sharing.

  5. Andrew (8 comments) says:

    Cool post. Definitely a useful tutorial with the wide range of uses that Facebook offers.

  6. Praveen (1 comments) says:

    Great post. This is my first exposure to FB dev kit. I have a “ePuzzle” game on iPhone that I developed last year with my 11 years old son for fun. Now almost after a year we are revising it to integrate it with FB so that players can post their scores from iPhone on their FB walls.

    Here is what I am thinking of and would like to know if you see any issue with the approach:
    1. A user finishes the game and get her score
    2. Optionally press the FB button to post the results on her FB account
    3. ePuzzle request user to provide her FB login credentials
    4. On successful login, ePuzzle posts the results and terminate the FB session.

    In other words, I would not use the UI provided in the SDK. I would just use the APIs to connect, post and logout.

  7. Ray Wenderlich (874 comments) says:

    Praveen, that definitely sounds like it would be possible since the Facebook API comes complete with source code. If you take a look at FBLoginDialog, you’ll see that all it’s really doing is making a call to facebook.auth.getSession, which you can emulate with your own code.

    Best of luck with your implementation, I think it’s great you’re teaching your son programming at such a young age! :]

  8. Simon (6 comments) says:

    Ray – first of all, thanks for a great post. Your tutorial was clear and simple, and filed with great info. I’ve been using the Facebook wiki, documentation, video, and sample code for help, but your code was much more straightforward. It’s people like you providing great resources that keep the community moving forward!

    I have one small question: a lot of the Facebook documentation refers to granting extended permissions, but your code doesn’t implement it. I am wondering why. Is it because you don’t need extended permissions for wall postings?

    My own modest app won’t be integrating anything other than wall postings, so I don’t want to implement that requests for extended permissions if I don’t have to.

    Can you shed any light on this?

    Thanks again.

  9. Ray Wenderlich (874 comments) says:

    Hi Simon – thanks, glad it came in handy!

    Yeah the extended permission thing confused me at the beginning too, and in my first iteration I added the code to grab the permission, until I realized it was unnecessary in my case.

    According to the Facebook Connect Wiki, the purpose of the “fb_stream” extended permission is so that your app can post to the user’s feed WITHOUT having the user seeing a confirmation dialog. But you don’t need the permission if you DO want the user to see a confirmation dialog.

    Since I kind of wanted the confirmation dialog to appear so the user knew exactly what was going on, I didn’t need to obtain this permission. But if you want to post “behind the scenes” as it were, you can ask for the “fb_stream” extended permission once and then post merrily away without showing dialogs in the future.

    Hope this helps!

  10. Simon (6 comments) says:

    Ray, thanks very much for the quick response.

    I guess I’m a bit confused about the different types of interaction between the App and Facebook. Having read your reply, and re-reading some of the documentation, my understanding is that there are three types of interaction/communication between an iPhone app and the Facebook API:

    Step 1) Connect the iPhone App to Facebook
    - Log-in with a Facebook account (e-mail and password), and grant permission for the connection between the app and Facebook, which includes wall posts (in one step).
    - Only needs to happen once.
    - Creates a Facebook session in code, which is persisted to the iPhone disk.

    Step 2) Post to the user’s Facebook Wall
    - As long as a valid Facebook session exists (e.g. Step 1), a post to the wall is possible.
    - Needs to happen every time that you want to post to the wall.

    Step 3) Grant Extended Permissions
    - Necessary for “behind the scenes” posting (i.e. user doesn’t confirm the posts to the wall), and other advanced calls to the Facebook API.

    Is that basically it?

    Since my app won’t be doing anything other than posting to the wall, and I don’t mind the user having to confirm every post, I am going to bypass the whole ‘Grant Extended Permissions’ step (Step 3), and stick to:
    Step 1) Connect the iPhone App to Facebook
    Step 2) Post to the user’s Facebook Wall

    I’m sorry for burglarizing your time, and thank you again for your help. I’m very grateful.

    -Simon

  11. Ray Wenderlich (874 comments) says:

    Well from what I understand you have it pretty close, except step 1 doesn’t actually grant permission for posting to the wall, the act of the user confirming the “post to wall” dialog is what gives your app permission to post to the wall.

    So yeah you can just do step 1 and 2 and bypass step 3 if you don’t mind having the user confirm the wall post. In fact this is exactly what the sample does!

    No problem glad I could help! :]

  12. Simon (6 comments) says:

    Terrific.
    Ray – thanks again for the clarification.

    Best,
    Simon

  13. Simon (6 comments) says:

    Ray:

    Do you know if it’s possible to inject anything other than the facebook name (as queried by the fql) into the dialog.attachment string?

    For instance, in your example, you use the NSString stringWithFormat to include the name of the Facebook user who is currently logged in to customize the ‘name’ section of the attachment, by passing _facebookName at the end of the dialog.attchment statement.

    I have an NSString variable that is built in my app based on some parameters in my app, and would like to pass it to the attachment string. The string variable is declared in my .h file and synthesized in the .m file.

    I haven’t been able to find anything in the documentation about this.

    Many thanks.
    -Simon

  14. Ray Wenderlich (874 comments) says:

    Hey Simon, yes definitely. The Facebook API specifies what the valid parameters are to the attachment field in the Facebook post attachment reference guide (such as name, caption, etc.) but as for what you fill in for each parameter, that is completely up to you.

    So for example, you could set the caption to be a dynamic string generated by combining three different member variables from your class. This has nothing to do with the Facebook API at this point, it’s just formatting the string with [NSString stringWithFormat].

    Does that make sense?

  15. Kuba (3 comments) says:

    Ray,

    I wonder if it’s possible to post updates to Facebook without using the dialogs from Facebook Connect. I was looking at the source code of Facebook Connect, but I cannot find the code responsible for this. Any hints?

    kind regards,
    Kuba

  16. Ray Wenderlich (874 comments) says:

    Hey Kuba, yeah I looked into that at some point to see if it was possible and it definitely is – check my response to Praveen above. I haven’t coded it up yet myself but sounds like a good idea for a future blog post!

  17. Kuba (3 comments) says:

    Thanks Ray!
    While waiting for your future post I will try to have a look at the code by myself.

  18. Elliott (7 comments) says:

    Hi Ray thank you for ace tut, I’m having trouble implementing this code so the fb button appears on the flipSideView of a utility App..can anyone help pls?

  19. viv (1 comments) says:

    Hi All the Post is really awesome.i have one query,i want to hard coded the username and password on facebook. so when my App launch it shows by default my username and password. Is it possible….?

  20. Ray Wenderlich (874 comments) says:

    @viv: AFAIK, the Facebook TOS requires you to use the standard Login Dialog Facebook provides, see this thread:

    http://forum.developers.facebook.com/viewtopic.php?pid=164827

    And I haven’t really investigated the Login Dialog class to check, but I would be surprised if there was a way to provide a username and password for that programatically. Even if you could, I wouldn’t recommend it, because then anyone using your app would know your password!

    If you’re just looking for Facebook to save the password that the user has enters in, Facebook automatically supports persisting Facebook sessions, which is basically what you want.

  21. Bhagirathsinh vala (1 comments) says:

    hi,

    it’s very good example.
    i need some example for accessing data from facebook.

  22. Michael Kaye (5 comments) says:

    Hi Ray,

    A while back I checked out the sample app and all worked well. Just checked it out again doesn’t seem to be working for me anymore. I’ve using SDK 3.1.3 and basically it looks like the login delegate aren’t getting called.

    Could you just do me a favour and check out your demo and let me know if its still working for you. If yes then at least I know it must be something at my end.

    Thanks, M.

  23. Jp (1 comments) says:

    Cool. Great explanation!!!

  24. Michael Kaye (5 comments) says:

    Ray,

    I think the issues I was experiencing were due to Facebook themselves. I’ve subsequently tried your demo and all is OK.

    Just wanted to say thanks for providing such useful information.

    Regards, Michael Kaye

  25. Ray Wenderlich (874 comments) says:

    @Michael: Awesome, thanks for letting me know!

  26. viralvora (1 comments) says:

    Thank you sir… you are really great and thanks to you a lot as you have taught me a lot things…

  27. bopanna S T (1 comments) says:

    @beatiful article… But how to get the login for as designed in my grade sample project.

  28. Mike (11 comments) says:

    sample project link is down :(

  29. Mike (11 comments) says:

    apologies, the link at the bottom of the article is fine :)

  30. Derek (1 comments) says:

    Hi Ray,

    Great Tutorial! You mention putting the FBSession code in a more centralized place for an app with more than one view. If I just place the FBSession code in the “MyGradesAppDelegate.m” file will it work the same or will I have to reference it differently from the other classes?

    Thanks.

  31. Simon (6 comments) says:

    Great question – I was wondering
    myself how to store the FB credentials in another view.

  32. Ray Wenderlich (874 comments) says:

    @Derek, Simon: It shouldn’t be a problem to store the FBSession object in your app delegate if you’d like, as there’s nothing “special” about FBSession, it’s just an object. You could store it in a member variable/property and then access it something like this:

    MyAppDelegate *delegate = [UIApplication sharedApplication].delegate;
    FBSession *session = delegate.fbSession;
    
  33. prasanna (2 comments) says:

    Is it possible to post to Facebook without using Facebook Connect dialogs?

  34. Ray Wenderlich (874 comments) says:

    @prasanna: AFAIK yes you technically can but it may be against Facebook’s policies. Good discussion here:

    http://stackoverflow.com/questions/2485771/iphone-sdk-facebook-connect-using-a-custom-login-dialog

  35. Sarthak (1 comments) says:

    Hi Ray,

    That was a cool tutorial. I am a complete newbie and implementing FB is taking quite some time.

    When I put the session code, I get 4 errors. Including Self Undeclared.

    How Do I solve them?

    Thank You

  36. Ray Wenderlich (874 comments) says:

    @Sarthak: Did you try comparing your code to the sample project?

  37. Altaf (1 comments) says:

    Hi ray,
    thx for the tutorial!
    its all working as expected (and better)
    but that is only until i try the debug mode.
    somehow i am not able to build in the release mode. all the errors that i am getting is due to fbconnect. any suggestions?
    thanks and thanks
    take care
    Altaf

  38. Shibin Moideen (1 comments) says:

    Really a great Thanks to you.. You did a great job. Thanks for the Post

  39. lokeshkunthoor (1 comments) says:

    Great tutorial, in fact i was searching for this kind of tutorial, was did some google search and finally found that this was the best.
    The way you write the article, source code was amazing.
    Thanks for your great support for all of the people who have been benefited from this.
    No longer i can wait, now i am following u on
    twitter:-)

  40. Ray Wenderlich (874 comments) says:

    @Altaf: I’d double check that when you were setting up your settings that you choose “All Configurations” and not just Release.

    @Shibin, @lokeshkunthoor: Thanks guys, glad the post was useful! :]

  41. smaug (5 comments) says:

    Hi!
    I found your blog useful, and more this post about facebook. In my try to use you example and copy it, I found a problem,at time to make a post, facebook denied me. I need to put in the facebook app configuration the apple ID from iphone application to make it work.

  42. Ray Wenderlich (874 comments) says:

    @smaug: Thanks! I’m not sure what you mean though, specifically what did you have to change to make it work?

  43. Mohan (1 comments) says:

    Hello Ray Wenderlich

    I want to get value from SQLite database and post it
    to facebook.

    I want to post message without open the dialog box of FBStreamDialog object.

    I don’t want to write any text in UserPromptMessage text box.

    Please, suggest me a right approach how can i implement this kind of functionality.

  44. Pascal Nicolas (1 comments) says:

    Hi Ray, thanks a lot for the great post!

    Can you please let me know if this is possible:

    - User installs iPhone app
    - User enters FConnect info and gives me permission to post to their facebook wall
    - This info is then stored on my server
    - My server periodically makes posts to user’s facebook wall (without the user triggering the facebook post from their iPhone)?

  45. Ray Wenderlich (874 comments) says:

    @Pascal/Mohan: Yes, you should be able to do that by getting the appropriate extended permission (“publish_stream”). See the following reference:

    http://developers.facebook.com/docs/authentication/permissions

    Note you will need to have the dialog to request the permission appear, but after that you should be able to post without the dialog.

  46. Russ Stinehour (1 comments) says:

    Thank you for your post and sample. I downloaded your sample. I inserted my app key and secret key. When I ran the app, the “Connect to Facebook” page displayed a blank page and returned. Am I missing something? Can you help with a possible explanation? Thank you.

  47. Ray Wenderlich (874 comments) says:

    @Russ: I just downloaded the sample project from the post and tried it here and didn’t have any issues – so I am not sure!

  48. smaug (5 comments) says:

    Hi ray,
    In the iphone app is not necesary change anything. But in the facebook app, I must edited the config in advanced tab, and add the apple Id to “Id. de la aplicación “iPhone”" or “Iphone application Id” i don’t know how is exactly in english. At right description of the field is “If you have an iPhone app using Connect, fill this in with your Apple-provided application ID.”
    Otherwise, i can’t post anything.

    PD: I’m sorry about my english.

  49. Ray Wenderlich (874 comments) says:

    @smaug: Wow, thanks for the update on this. Not sure why it worked for me – but I updated the post with your tip in case other people get hit by this!

    Thanks again!

  50. Honey Sharma (3 comments) says:

    Hi,
    Can you show me way so that I can implement “Like” button of facebook in my app?.Please help with some code.

  51. Asif Ali (1 comments) says:

    I can’t build successfully, it’s giving 104 errors after importing the FBConnect

  52. Ray Wenderlich (874 comments) says:

    @Honey: I haven’t done this myself so not sure. However here’s a discussion on the Facebook forums to get you started:

    http://forum.developers.facebook.com/viewtopic.php?pid=228062

    @Asif Ali: This sounds like something didn’t go right with importing Facebook into your project or configuring your project settings. Try carefully following the instructions at:

    http://github.com/facebook/facebook-iphone-sdk/

  53. Pablo Romero (1 comments) says:

    Hey man, great post! this is the second time I finish in you blog searching some good iPhone example.

    Thanks!
    Pablo

  54. IHSAN KHAN (1 comments) says:

    Sir,
    Is it possible to chat my face book friends through iPhone Application.
    Reply me as soon as possible.

  55. Ray Wenderlich (874 comments) says:

    @Pablo: Thanks much!

    @Ihsan: AFAIK there is no way to do this. However if you find there is please let me know :]

  56. sanjeev sharma (2 comments) says:

    Thanks for this nice tutorial,
    can you tell me how to upload pictures to facebook from my app.

    Thanks & Regards
    Sanjeev kr. sharma

  57. Ray Wenderlich (874 comments) says:

    @sanjeev: Stay tuned for a new article series coming to this blog soon *hint hint*! :]

  58. sanjeev sharma (2 comments) says:

    Thanks a lot Mr. Ray
    Actually need to implement uploading pictures on facebook little quick

  59. Michael Kaye (5 comments) says:

    Sanjeev.

    It is straight forward. Look at the example app from Ray. Check out the Facebook api.

    No one is going to do the work for you. Sorry if I sound harsh but sometimes you just have to jump in and try for yourself.

    Mr Kaye.

  60. Venkat (2 comments) says:

    hello Ray, i used this code to post the msg on users wall.But its not work…. is this is the way for posting message on users wall without prompting dialog.i missed any thing…

    - (void)askPermission:(id)target {
    FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
    dialog.delegate = self;
    dialog.permission = @”publish_stream”;
    [dialog show];
    }

    - (void)publishFeed:(id)target {

    NSString *message = @”Venkat sent test message from iPhone”;

    NSString *attachment = @”{\”name\”:\”Facebook Connect for iPhone\”,\”href\”:\”http://developers.facebook.com/connect.php?tab=iphone\”,\”caption\”:\”Caption\”,\”description\”:\”Description\”,\”media\”:[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\”properties\”:{\”another link\”:{\”text\”:\”Facebook home page\”,\”href\”:\”http://www.facebook.com\”}}}”;/*attachment = @”{\”name\”:\”test name\”,\”caption\”:\”test caption\”,\”description\”:\”test description\”";
    attachment = [attachment stringByAppendingFormat:@"\"user_lat\":\"%f\",", 1.03];
    attachment = [attachment stringByAppendingFormat:@"\"user_lng\":\"%f\",", 103.10];
    attachment = [attachment stringByAppendingString:@"}"];*/

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setObject:message forKey:@"message"];
    [params setObject:attachment forKey:@"attachment"];

    NSString *action_links = @”[{\"text\":\"buUrp with iPhone\",\"href\":\"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=297106176&mt=8\"},{\"text\":\"buUrp with Android\",\"href\":\"http://market.android.com/search?q=pname:com.buuuk.buUuk\"},{\"text\":\"About buUuk\",\"href\":\"http://www.facebook.com/apps/application.php?id=57631608493\"}]“;
    [params setObject:action_links forKey:@"action_links"];

    /*NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
    message, attachment, action_links, @" " ," ",@"NULL",@"true",nil ];*/

    [[FBRequest requestWithDelegate:self] call:@”facebook.Stream.publish” params:params];
    }

  61. elixir (1 comments) says:

    Hi Ray,
    Thanks for this nice tutorial.
    My issue is how to get the post id, when a user post a message on the wall using this facebook connect SDK. Goggled it, wasn’t able to find a soln.Have to implement this feature in one of my Apps.

    Thanks in advance.

  62. Ray Wenderlich (874 comments) says:

    @Venkat, Elixir: I’d suggest checking out the Facebook Connect forums for questions like this:

    http://forum.developers.facebook.com/viewforum.php?id=37

  63. Venkat (2 comments) says:

    Thanks Ray… i found the solutions from the website

    http://www.cocos2d-iphone.org/forum/topic/3392

    Regards
    Venkat

  64. Dev (3 comments) says:

    Nice article Ray. Thanks. Was trying to figure out how to resume an fb session without having the user login again and stumbled upon this.

    I can’t get the session to resume using the resume method. The session:didLogin method just doesn’t get called. Any ideas what could be going wrong?

    Thanks again for the tut.

  65. Ray Wenderlich (874 comments) says:

    @Venkat: Great, and thanks for posting the topic so others can benefit!

    @Dev: Hmm… not sure maybe try setting a breakpoint in FBSession::save and make sure that code is getting called somewhere?

  66. satheesan (1 comments) says:

    Thank you Ray,
    Can I set my facebook username and password in code itself..?I am new to i-phone development and Please help me with some code.

  67. Dev (3 comments) says:

    Not sure what happened but it works now :) The session gets saved, resumes and posts fine!

    Thanks again.

  68. Ray Wenderlich (874 comments) says:

    @satheesan: AFAIK according to the Facebook terms of service, you cannot set the facebook username and password yourself, the user needs to do it with the login dialog, for security reasons. However, you can request an extended permission so that once the user logs on once, you get a permanent access token so you can always log in automatically in the background.

    @Dev: w00t!

  69. Clarence (4 comments) says:

    Say Ray,

    Strange thing, when I change the fallowing:
    static NSString* kApiKey = @”8fa673a06891cac667e55d690e27ecbb”;
    static NSString* kApiSecret = @”325a4c580253c7619313baad5712cc2a”;

    to my key and secret, it just hang and never logs in, any ideas?

    CC

  70. Tiny Technician (5 comments) says:

    Great article…just finished implementing some FBConnect action into my App. Needed to tweak it a bit to allow my App to publish to stream without prompt/confirmation from user (thanks @Venkat for the link, that helped me with the auto-publish logic).

    Still need to implement the ability to automatically connect to facebook once the user has already logged in once. Would greatly appreciate it if anyone has a link for this, else when I find the solution I’ll be sure to include it here.

    Thanks again Ray!

  71. Lee (6 comments) says:

    Ray,

    I’m a new developer (around a week old new :P ) and I must admit you are the most thorough source on the net I’ve found yet, a lot of the developer forums are somewhat abusive to questions.

    Your source and coding is very easy to understand I visit here often and have not yet felt the need to question or ask for help with your guides.

    Very nice, I’ve already recommended you to several people.

  72. Ray Wenderlich (874 comments) says:

    @Clarence: Hm, I haven’t seen that myself, did you ever figure it out?

    @Tiny Tech: You can request the offline_access permission, which will allow you to login without prompting the user once they grant permission:

    http://developers.facebook.com/docs/authentication/permissions

    @Lee: Thanks for the kind words, and welcome to iOS development! I love your hat in your picture btw :]

  73. Clarence (4 comments) says:

    Yup got thank you very much.

    CC

  74. sagi (2 comments) says:

    Hi Ray, great article, I used it to the letter and it worked great in the previous SDK, but recently FB released a new SDK, and the same exact JSON block does not work. More specifically, it complains that “media should be an array” :-( I’d appreciate if you could shed some light, maybe you had some experience already with the new sdk?

    thanks…

  75. Pats (1 comments) says:

    So, there is no way to test your app without register it at FB? I don’t want to register an app which is not finished at all and I just want to test the upload of an image to FB.

  76. Tiny Technician (5 comments) says:

    Hey Ray, thanks for the tip.

    I actually figured out what I was doing wrong (and why the login dialog kept popping up even after I resumed the session).

    Was running into a bit of a race condition where I was checking if the user had permissions before the permissions were loaded from the session/user info.

    This then caused my app to throw up the FBPermissionDialog which seems to turn into a login dialog if the user already has the requested permission (at least that’s what seemed to happen on my end). Either way, the basic [session resume] command worked.

    Thanks again for all the great tutorials!!

  77. Qamar Suleiman (1 comments) says:

    Hi Ray ..I am becoming a fan of yours day by day..

    Is there any way I could upload my videos to facebook using FBStreamDialogue of FBRequest.

  78. Ray Wenderlich (874 comments) says:

    @sagi: I haven’t tried out the new SDK yet. If/when I do, I’ll probably update this tutorial. In the meantime, if you figure it out, please drop a note here so others can benefit!

    @Pats: You can register an app at Facebook and then just not “release” it, so nobody will see it. That’s what I did for testing purposes.

    @Tiny Tech: Ah that makes sense! Thanks for sharing!

    @Qamar: I’ve never tried uploading videos, but this link may help:

    http://developers.facebook.com/docs/reference/rest/video.upload

  79. zobo (2 comments) says:

    Another fantastic tutorial. Thanks Ray – you are a godsend to the iPhone and cocos2d developer community!

    @Clarence: I’m having the same problem you had. How did you resolve it?

  80. Clarence (4 comments) says:

    Make sure you log out with the sample key and change it to yours and run it.

    Hope is helps!

    CC

  81. Clarence (4 comments) says:

    Say anyone know how make it not prompt you for a comment? I would like to send the post based on game score and skip the input screen.

    Thanks again

    CC

  82. ben (5 comments) says:

    hi, is it possible to share the image with my friends in facebook from iphone app?

  83. Muzammil (4 comments) says:

    Hi Sir,

    I have made an app to running in background with the BackgroundMode set to location. The application works well when it enters the background state but after 10 minutes or so, it stops responding anymore. Perhaps it gets suspended.
    What I want to do is run the application in the background forever without any time limit. Please guide me how can I achieve this.

    Thanks and Regards,
    Muzammil

  84. zobo (2 comments) says:

    @Clarence: that was it, thanks!

    @Ray Wenderlich: Any plans for a “post game score to Twitter using OAuth” tutorial? :D

  85. Ray Wenderlich (874 comments) says:

    @Clarence: Thanks so much for posting your solution! If I recall, if you get the offline_access permission you can login/post without prompting the user anymore.

    @Ben: For posting images, check out this tutorial:

    http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-photos-and-add-a-like-button-from-your-iphone-app

    @Muzammil: I recommend watching WWDC Session #109: Adopting Multitasking on iPhone OS, Part 2.

    @zobo: Added to the idea list, thanks!

  86. Elliott (7 comments) says:

    Hi Ray and everyone else!

    I found a bug in the Facebook source code today.

    If you use Facebook Connect on an iPhone 4 (Device or Simulator) on logging in and loading the feed dialog you will not see an Activity Indictor here, so the user will not be getting visual feedback that anything is happening.

    I fixed the problem by going into FBDialog.m and replacing:

    _spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
    UIActivityIndicatorViewStyleWhiteLarge];

    to:

    _spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
    UIActivityIndicatorViewStyleGray;

    Problem fixed now works great with all devices. Hoped this would be helpful!!?

    Elliott =]

  87. Elliott (7 comments) says:

    Whoops;

    _spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
    UIActivityIndicatorViewStyleGray];

  88. DTSL (1 comments) says:

    This is old stuff Ray. Not compatible anylonger.

  89. Michael kaye (5 comments) says:

    DTSL – what a bloody useless comment.

    Why don’t you check out Ray’s latest blog posts on the posting to Facebook.

    Anyway thinking about it, I’m still using this approach and it works for me.

  90. Tyler (5 comments) says:

    I have followed your tutorial, and for the most part everything works just fine. However, I have ran into one very odd problem. I have a tab bar app I have built for a church. On one view I want to let them login to post an invitation to church. On another, there is a blog where they can post the blog article to their facebook wall. I was having issues where after they logged in, it would not show the post to wall, so I had to set the loginDialog to initWithSession:_session. After I did that, it worked fine; on one view. The other one crashes and gives me the called a nil _session key. I thought maybe I made a typo so I copied and pasted the code from the working view directly into the non-working view and tested, and again got the same problem. Why would it work in one view and not the other? Here is the code I am using:
    .h

    #import
    #import
    #import
    #import “FBConnect.h”
    @interface SixthView : UIViewController {
    IBOutlet UIWebView *steve;
    IBOutlet UIActivityIndicatorView *activity;
    NSTimer *timer;
    NSString *currentURL;
    NSString *title;
    FBSession* _session;
    FBLoginDialog *_loginDialog;
    UIButton *_postGradesButton;
    UIButton *_logoutButton;
    NSString *_facebookName;
    BOOL _posting;
    NSString *postentry;
    NSString *text;
    }
    - (IBAction)done;
    - (IBAction)action:(id)sender;
    - (IBAction)postGradesTapped:(id)sender;
    - (IBAction)logoutButtonTapped:(id)sender;
    - (void)postToWall;
    - (void)getFacebookName;
    -(void)displayComposerSheet2;
    -(IBAction)showPicker:(id)sender;
    -(void)displayComposerSheet;
    -(void)launchMailAppOnDevice;
    @property (nonatomic, retain) UIActivityIndicatorView *activity;
    @property (nonatomic, retain) NSString *text;
    @property (nonatomic, retain) NSString *postentry;
    @property (nonatomic, retain) NSString *currentURL;
    @property (nonatomic, retain) NSString *title;
    @property (nonatomic, retain) FBSession *session;
    @property (nonatomic, retain) IBOutlet UIButton *postGradesButton;
    @property (nonatomic, retain) IBOutlet UIButton *logoutButton;
    @property (nonatomic, retain) FBLoginDialog *loginDialog;
    @property (nonatomic, copy) NSString *facebookName;
    @property (nonatomic, assign) BOOL posting;

    @end
    .m

    #import “SixthView.h”
    #import

    @implementation SixthView
    @synthesize activity;
    @synthesize postentry;
    @synthesize currentURL;
    @synthesize title;
    @synthesize session = _session;
    @synthesize postGradesButton = _postGradesButton;
    @synthesize logoutButton = _logoutButton;
    @synthesize loginDialog = _loginDialog;
    @synthesize facebookName = _facebookName;
    @synthesize posting = _posting;
    @synthesize text;

    - (void)viewDidLoad {
    [steve loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://resurrectedliving.wordpress.com"]]];
    timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];

    // Set these values from your application page on http://www.facebook.com/developers
    // Keep in mind that this method is not as secure as using the sessionForApplication:getSessionProxy:delegate method!
    // These values are from a dummy facebook app I made called MyGrades – feel free to play around!
    static NSString* kApiKey = @”REMOVED FOR PRIVACY”;
    static NSString* kApiSecret = @”REMOVED FOR PRIVACY”;
    _session = [[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];

    // Load a previous session from disk if available. Note this will call session:didLogin if a valid session exists.
    [_session resume];

    [super viewDidLoad];
    }
    -(void)tick {
    if(!steve.loading)
    [activity stopAnimating];
    else
    [activity startAnimating];

    }

    - (IBAction)postGradesTapped:(id)sender {
    _posting = YES;
    // If we’re not logged in, log in first…
    if (![_session isConnected]) {
    self.loginDialog = nil;
    _loginDialog = [[FBLoginDialog alloc] initWithSession:_session];
    [_loginDialog show];
    }
    // If we have a session and a name, post to the wall!
    else if (_facebookName != nil) {
    [self postToWall];
    }
    // Otherwise, we don’t have a name yet, just wait for that to come through.
    }

    - (IBAction)logoutButtonTapped:(id)sender {
    [_session logout];
    }

    #pragma mark FBSessionDelegate methods

    - (void)session:(FBSession*)session didLogin:(FBUID)uid {
    [self getFacebookName];
    }

    - (void)session:(FBSession*)session willLogout:(FBUID)uid {
    _logoutButton.hidden = YES;
    _facebookName = nil;
    }

    #pragma mark Get Facebook Name Helper

    - (void)getFacebookName {
    NSString* fql = [NSString stringWithFormat:
    @"select uid,name from user where uid == %lld", _session.uid];
    NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
    [[FBRequest requestWithDelegate:self] call:@”facebook.fql.query” params:params];
    }

    #pragma mark FBRequestDelegate methods

    - (void)request:(FBRequest*)request didLoad:(id)result {
    if ([request.method isEqualToString:@"facebook.fql.query"]) {
    NSArray* users = result;
    NSDictionary* user = [users objectAtIndex:0];
    NSString* name = [user objectForKey:@"name"];
    self.facebookName = name;
    _logoutButton.hidden = NO;
    [_logoutButton setTitle:[NSString stringWithFormat:@"Facebook: Logout as %@", name] forState:UIControlStateNormal];
    if (_posting) {
    [self postToWall];
    _posting = NO;
    }
    }
    }

    #pragma mark Post to Wall Helper

    - (void)postToWall {

    FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
    dialog.userMessagePrompt = @”Enter your message:”;
    dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"%@\",\"href\":\"%@\",\"caption\":\"Check out this article by Scott Elliott\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"http://www.316apps.com/lagrange.jpg\",\"href\":\"http://resurrectedliving.wordpress.com\"}]}”,
    self.title, self.currentURL];
    [dialog show];

    }

    #pragma mark Memory Cleanup

    - (void)viewDidUnload {
    self.postGradesButton = nil;
    self.logoutButton = nil;
    }

    - (void)dealloc {
    [_session release];
    _session = nil;
    [_postGradesButton release];
    _postGradesButton = nil;
    [_logoutButton release];
    _logoutButton = nil;
    [_loginDialog release];
    _loginDialog = nil;
    [_facebookName release];
    _facebookName = nil;
    [super dealloc];
    }

    @end

  91. Ray Wenderlich (874 comments) says:

    @Elliott: Cool, thanks for posting the info, should be useful to others!

    @DTSL: It’s true that a new Facebook SDK has come out since I wrote this post (from 27 Jan this year!), so to make sure people are aware of that I’ve made a note at the beginning of this post. Maybe I’ll write an article on the new SDK when I have some time. But Michael is correct, this method still does work with the old Facebook SDK, which is still available. Also like Michael mentioned, there are also some tutorials on this site on how to use the new Open Graph API “under the hood”.

    @Tyler: Elliott and I ran into this problem once as well. There are a bunch of problems if you try to initialize a Facebook session more than once (such as you’d be doing if you add the code to two separate view controlelr). In apps moving forward, I’ve moved all Facebook code into a separate Facebook Helper class, and give any view controllers that want to work with Facebook a pointer to this class.

  92. glasgorilla (2 comments) says:

    do u know of any bug that would be causing the wall posts to fail on fb accounts created in uk, whilst being successful on fb accounts created elsewhere?

    any feedback much appreciated.

  93. Ray Wenderlich (874 comments) says:

    @glasgorilla: No idea, haven’t run into that problem myself! However if you figure out the reason please post here so others may benefit.

  94. Glasgorilla (2 comments) says:

    Looks like server specific fb bug. Cheers

  95. Tyler (5 comments) says:

    @Ray, Thanks for the response. Glad it wasn’t just me running into that problem. If everything FB is in one class, do you just do different -(void) statements for if you want different styles of Publish to Wall?

  96. Farrah (1 comments) says:

    Hello Ray good work.
    Can you please tell that how can I use “Attach” feature of facebook for url’s in which they fetch thumbnail, title and description of any url pasted by user and then he/she can share it using ‘Share’ button.

  97. Ray Wenderlich (874 comments) says:

    @Tyler: You could do that, but it would probably be cleaner to just take in the parts that change (like the caption, link, etc.) as parameters to your postToWall method.

    @Farrah: I’d suggest experimenting a bit to see how to get the results you’re looking for – post a link to a wall, see if Facebook automatically pulls in a thumbnail from the site, if not use the Graph API to pull back the details of a wall post that IS formatted the way you want to figure out how they set it up, then reproduce it. If you get stuck, might want to try the Facebook SDK forums:

    http://forum.developers.facebook.net/

  98. Nick (7 comments) says:

    Thanks for this.

    Compiles on both my iPhone 3 and my iPad, but when I press the ‘post to facebook’ button on iPad, the buttons in the dialog box do not work. Does this not work for iPad?

  99. Tyler (5 comments) says:

    Thanks,
    One problem I have is that sometimes when I log in, it won’t pull up the publish to wall window. It disappears and if I close the app and press again, since I’m still logged in, it will finally let me publish to wall.

  100. Ravi (4 comments) says:

    Hi ray,

    I want to post comments to facebook from iphone.
    Iam using old rest api.
    How to achieve this.Iam passing session and session secret from iphone to a php page from their iam trying to get status(just for example) of user but failed.

    Ravi Pulluri.

  101. Ray Wenderlich (874 comments) says:

    @Nick: I make no guarantees about this tutorial on the iPad, as I haven’t tried it out there. If you’re having troubles, you might want to use the newer Facebook SDK, which I’d imagine works fine on the iPad.

    @Tyler: I’d suggest setting breakpoints in the code to figure out what’s going on.

    @Ravi: I haven’t played around with PHP facebook integration yet, sorry! Maybe try the Facebook developers forums for this.

  102. vicky (1 comments) says:

    Ray,

    Please tell me how can post on specific friends wall from my friends list. I am able get friends list not able to post message.

    Regards,
    Vicky

  103. Ray Wenderlich (874 comments) says:

    @vicky: Haven’t played around with it yet myself, sorry!

  104. satheesan.op (6 comments) says:

    @vicky:This link may help you http://developers.facebook.com/docs/api
    Using this you can find the ID of particular friends ,and using that id/feed you can post to any friends wall.

  105. ramdas (1 comments) says:

    I inlcuded the FBConnect and could run and compile the code without including the header search path

    however when I try to deploy ( ad hoc deployment) on iphone – it gives me a code signing error

    When I remove the FBConnect from project – things work fine ( the ad hoc deploymnet ) to the iphone

    what gives?
    ~ramdas

  106. Milad (1 comments) says:

    Thanks for your article can i write one code for loading freind list in this app thanks?
    please help me and give me one sample code

  107. Ray Wenderlich (874 comments) says:

    @santheesan: Thanks for helping out @vicky!

    @ramdas: Did you follow the instructions for how to include FBConnect to your project exactly as specified on its project page? Might want to double check. I don’t see why adding Facebook Connect would cause any code signing errors – there must be something else going on.

    @Milad: Sorry, I don’t have time to write any further sample code for this at this point. I’d suggest experimenting with it, you can figure it out :]

  108. mayukh Varghese (7 comments) says:

    hey RAY
    great post your post is the only one i could find on the net that actually works ,great job!!! i mean it.
    Just one question though why have you put “NOT clicked” in the below step why is it so important not to copy the items to the project file

    “3)Drag the FBConnect group to your project. When the prompt appears, make sure “Copy items into destination group’s folder” is not clicked.”

  109. Danny (2 comments) says:

    As always, excellent tutorial. I used this as the basis for implementing Facebook on previous applications. The way authentication works in the new Facebook SDK is very confusing (oAUTH). I was wondering if there was any chance we may be getting a new tutorial which uses the new FB-SDK.

  110. Ray Wenderlich (874 comments) says:

    @mayukh: Oh just to make sure you don’t duplicate the Facebook SDK files into your project, and instead just add links to the files to where they already exist.

    @Danny: That is definitely high on my priority list since the Facebook tutorials here are out of date now, but it’s just a matter of finding time :]

  111. mayukh Varghese (7 comments) says:

    HI RAY
    thank you for the responce. The facebook connect u created was for a view based application how would i go about adding this to a cocos2d application like your Ninja game,to maybe post your score on your wall??

    thank you in advance :)
    Mayukh

  112. Teej (2 comments) says:

    Hey Ray, I’ve been reading your articles and trying to put them to use in my own app. I have a problem though, every thing I try seems to be a one off in the simulator. This project and when I implement it in my own project. It seems to work once, and then if I try to go through and post again the program either crashes or refuses to pop up a post to wall dialog. Is this because the FBConnect API is so out of date, or is there something else I need to do, such as separate the post and log in code into different methods and call them differently?

  113. Teej (2 comments) says:

    Let me be more clear. For example on your project, if I log out after posting and click the post to wall again, the dialog comes up and lets me try to log back in, but crashes before the post to wall dialog shows? or if I click the post button without logging out, it crashes immediately. This is all new to me, so I apologize if my questions are basic.

  114. Sushant (1 comments) says:

    Hi Ray!
    Thanks for the great tutorial! :)
    Can you tell me how can I send hard coded text in the textbox (which in your case is: “Custom user message”).
    Its like when the user log in, the wall page appears with a default text in the text box and the user just has to hit the share button!
    Thanks :)

  115. Ray Wenderlich (874 comments) says:

    @mayukh: There’s a nice tutorial on that you can check out here:

    http://www.cocos2d-iphone.org/archives/590

    @Teej: I just downloaded the sample project and posted to Facebook, logged out, posted again, and it made 2 posts without a crash. Are you using the sample project from this site? If so, what errors do you see in the console log?

    @Sushant: Not sure if there’s a way to do that… but if you figure out a way please post here so others can benefit :]

  116. mayukh Varghese (7 comments) says:

    hey RAY
    the link u sent me when i open the tutorial ,its just a blank page saying “cheers” :D?????????

  117. mayukh Varghese (7 comments) says:

    oh sorry ray,the other link has something ,my bad

  118. Imran ul Hassan (1 comments) says:

    Hey Ray!!
    Thanks for such a great tutorial… I downloaded it and getting a cool experience….
    could u guide me how to send a string from code instead of sending it from dialog (message publish on the wall) thanx in advance

  119. Muhammad Amir Pervaiz (2 comments) says:

    Hi Ray:
    Thanx for the the great tutorial but I am wondering is there any way of posting message to fb programmatically? Specifically we have to publish through code instead of manually.any insights.
    Thanx

  120. Muhammad Amir Pervaiz (2 comments) says:

    lemme check out the link you posted yesterday
    thanx

  121. shilpa (5 comments) says:

    Can you tell me how can i send action link using graph api. I have tried something like this,

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

    NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
    @"action link",@"name",@"http://www.postcardexpress.com",@"link",
    nil], nil];
    NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
    hi, @"message",
    actionLinksStr, @"actions",

    nil];
    [_facebook requestWithGraphPath:@"me/photos"
    andParams:params
    andHttpMethod:@"POST"
    andDelegate:self];
    [img release];

    But not getting the required result!

  122. Adam (1 comments) says:

    What are the limits for number of Wall Post invites your iPhone app can send?

    And, once a user reaches that limit, how long will it take before that user is able to make additional wall posts?

    Thanks

  123. shahzeb (1 comments) says:

    nice post. This post is different from what I read on most blog. And it have so many valuable things to learn.
    Thank you for your sharing!

    Nice information provided here which is very useful to everyone…I am not a huge fan of this side, there do seem to be a lot these days…thanks for posting…Let me know more about this one

    Nice post! You have worked hard on jotting down the essential information. Keep sharing the good work in future too.

    This post is very informative and useful.. Thanks for sharing knowledge..

  124. Sudhanshu Srivastava (3 comments) says:

    Hey!! please tell me how I can give a link to the caption with my post on facebook.

  125. Ray Wenderlich (874 comments) says:

    @Muhammad: As noted in one of the other comments above, you can request the offline_access permission, which will allow you to login without prompting the user once they grant permission:

    http://developers.facebook.com/docs/authentication/permissions

    @shilpa: Check out this tutorial for an example:

    http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-photos-and-add-a-like-button-from-your-iphone-app

    @Adam: No idea, I’d suggest asking on the Facebook developer forums here:

    http://forum.developers.facebook.net/

    @shahzeb: Thanks so much for the kind words! :]

    @Sudhanshu: Sorry, not sure what you’re asking.

  126. Elliott (7 comments) says:

    Hi Ray, hope all is well? I had an answer for Adam;

    Hi Adam, in answer to your question facebook says;

    “Based on the affinity users show for your application’s use of the Facebook platform through their interactions, your application is allocated certain abilities and limits. This is the functionality currently allocated to your application. These values will change over time depending on how users interact with your application. All integration points have a set of limit values and the threshold bucket column tells you which of these limits buckets your application is in for that integration point. Bucket 1 is the smallest allocation bucket.”

    I have an App called iSnaffle that has been given a Bucket of 10/14 that gives my users a threshold of 32 posts a day which to be fair seems more than plenty.

    If you go to your Facebook homepage then go Applications/Insights/Diagnostics then look under Allocations, you will find this information.

    Hope this helps? Elliott

  127. Sudhanshu Srivastava (3 comments) says:

    Hi Ray, Let me explain what I mean by my earlier comment. I have made an application that publishes an audio file to facebook, this audio file has title,caption and description with it and now I want caption to be a clickable link. so I want to know that how I can give a link to the caption text in my iPhone application.

    Thanx for your reply….!

  128. jonmars (1 comments) says:

    Hi Ray

    First, Thanks!

    I have just one question : what is the best way to differentiate request results (into the didload() function) for identical requests. Because the user can cancel an operation, or results can naturally be sent in a different order than requests. Some people talk about sublclassing FBrequest.

    I’m looking forward to hearing from you, thanks!

  129. Sudhanshu Srivastava (3 comments) says:

    Hi Ray,

    Can you plz tell me how can I publish an audio file to facebook wall using Graph API, I can successfully do the same using Old Rest API but I want to know if it is possible to do the same with New Graph API.

    Thanx….!!!

  130. Rohit (4 comments) says:

    Sir, Thanks for the tutorial. :). Nice One.

    But instead i want to taunt some friend of mine on facebook with some text, how should i do that?
    Or
    I want to post some text on my selected friend’s wall.
    How should i do that?

    Thanks in advance.

I'd love to hear your thoughts!