GET THE LATEST CODE FROM HERE: http://code.google.com/p/iphone-facebook-twitter-connect-easy-integration-tool/
PLEASE JOIN THE PROJECT

This project is now obsolete since I found facebook released a great class!!
check out here : http://github.com/facebook/facebook-ios-sdk

Today most of the applications we build have a common feature: Socialize! One common way to achieve this my integrating Facebook within the app.

In my earlier post I have shared a helper class for paginating data. Today I will share how I integrate facebook connect in iPhone apps. I humble admit I am a lazy, if not busy, developer who doesn’t like to write same code again again.

For iPhone applications FacebookConnect is the only way to integrate facebook social features. Facebook team has developed a sdk for iPhone. A sample code showing the use and integration of Facebook Connect in your application. This is quite simple and also tons of tutorials, forums, e-books and videos are out here on the web.

Well, I’m not gonna add few more grams on that! Rather I am going to share how I integrates facebook connects into my apps.

Firstly, let us see what are the steps to add facebook connect. You can also check out this tutorial on facebook wiki or watch the video Implement Facebook Connect on the iPhone in 5 minutes.

Basically the steps for publishing a feed are:

1. Download the sdk.

2. Add the connect source file in your project.
project
3. Update the settings to make FBConnect.h in you header path.

4. In the controller class, have session member variable, many delegate methods.

5. Have a login button to show the login prompt.

6. Once logged in, prepare an attachment json string and show the feed dialog.

These steps are quite simple but if you are a busy programmer and need to work on many projects these steps may be little bothering since you have to rewrite all the codes for loggin in, showing dialogs, handle login events etc.

So, I just encapsulated these repetitive work into a class named FacebookAgent and defined a simple protocol to work on.

Lets see how we can use it.

Objective: Create a simple view based application and publish a feed using FacebookAgent.

1. Download this folder FacebookAgent.zip.

It also includes facebook connect sdk. So you don’t need to add this sdk elsewhere or even update any project settings for this purpose.

2. Create a new project, name it FacebookAgentTest. Righ click on the project in the XCode and select Add existing files. Add the FacebookAgent Folder to your classes. Check copy the source files.

Add FacebookAgent folder to your project

3.  In the FacebookAgentTestViewController.h, import FacebookAgent.h and implement protocol FacebookAgentDelegate.

@interface FacebookAgentTestViewController : UIViewController {
...

4. Declare a member variable of type FacebookAgent.

FacebookAgent* fbAgent;

5. Open FacebookAgentTest.m and initialize fbAgent in viewDidLoad method.

fbAgent = [[FacebookAgent alloc] initWithApiKey:@"PLACE YOUR FACEBOOK APPLICATION API KEY"
										  ApiSecret:@"PLACE YOUR FACEBOOK APPLICATION API SECRET"
										   ApiProxy:nil];
	fbAgent.delegate = self;

6. Declare an IBAction method in the FacebookAgentTest.h file.

-(IBAction)updateStatus:(id)sender;

7. Define the above method in FacebookAgentTest.m file.

-(IBAction)updateStatus:(id)sender{
}

8. Open FacebookAgentTestViewController.xib and add a button in the view and connect the above method on its touchesUpInside signal.

9. Now just add the following lines in the updateStatus method to publish a feed!

-(IBAction)updateStatus:(id)sender{
[fbAgent publishFeedWithName:@"Hellow world"
					 captionText:@"how are you?"
						imageurl:@"http://amanpages.com/wordpress/wp-content/uploads/2009/12/logo2.png"
						 linkurl:@"http://amanpages.com/"
			   userMessagePrompt:@"What do you think:"];
}

This code will first check if the user is logged in. If logged in it will show the feed dialog.
If the user is not logged in already, first the login dialog will be shown, after logging in, the feed dialog will be shown automatically!

But one minute, there is one require method in the FacebookAgentDelegate protocol. So, you need to define this:

- (void) facebookAgent:(FacebookAgent*)agent loginStatus:(BOOL) loggedIn{
}

Above method is called when the user logs in or logs out of the facebook. If you use any login button which is very likely, you may change the button title here.

10. Try updating your status. For this use this line:

[fbAgent setStatus:@"status from iPhone 1"];

This will first check if the user is logged in. if not logged in, then it will show the login prompt first.
After log in it will check if extended permission is enabled for this app. if not it will show the permission dialog.
Having given the permission, it will change the user status.

BUT.

11. You need to two more FacebookAgentDelegate method if you want to change status:

- (void) facebookAgent:(FacebookAgent*)agent requestFaild:(NSString*) message{
}
- (void) facebookAgent:(FacebookAgent*)agent statusChanged:(BOOL) success{
}

12. Thats all :) Run the app!

You can look into the FacebookAgent.h for more detail. It is well documented. If you still have some question shoot here or drop me mail.
Feel free to use this classes without any restriction but I will appreciate if you let me know in which app you are using it :)

What can be done now using FacebookAgent:
1. Fetch user name:
For this after initialization, set shouldFetchUsernameAfterLogin = YES.

fbAgent.shouldFetchUsernameAfterLogin = YES

and also define the corresponding delegate method:

- (void) facebookAgent:(FacebookAgent*)agent didLoadName:(NSString*) name{
    //use the name
}

2. Make your own attachment and publish a feed.

// this method has some over loaded versions too
- (void) publishFeed:(NSString*)attachement;

3. Publish feed by passing, name, caption, image and link url.

// this method has some over loaded versions too
/**
 * Let the agent make attachement for you. You just pass the information
 *
 */
- (void) publishFeedWithName:(NSString*)name
			 captionText:(NSString*)caption
					   imageurl:(NSString*)url
						linkurl:(NSString*)href
			  userMessagePrompt:(NSString*)prompt;

4. upload a photo

- (void) uploadPhoto:(NSString*)imageurl;

6. ask for extended permission

- (void) askPermission;

7. login and logout

- (void) login;
- (void) logout;

The delegates also offers some handy callback options like:

/**
 * Must define this method if setStatus is called
 *
 * This method is called when user status is changed either successfully or not
 */
- (void) facebookAgent:(FacebookAgent*)agent statusChanged:(BOOL) success;

/**
 * Must define this method if shouldFetchUsernameAfterLogin is set YES
 *
 * This method is called after the agent fetched facebook profile name
 */
- (void) facebookAgent:(FacebookAgent*)agent didLoadName:(NSString*) name;

/**
 * Must define this method if uploadPhoto is called
 *
 * This method is called after photo is uploaded
 */
- (void) facebookAgent:(FacebookAgent*)agent photoUploaded:(NSString*) pid;

/**
 * Must impement this method if any of the above method is defined
 *
 * This method is called if the agent fails to perform any of the above three actions
 */
- (void) facebookAgent:(FacebookAgent*)agent requestFaild:(NSString*) message;

@required

/**
 * This method is called if after login or logout
 */
- (void) facebookAgent:(FacebookAgent*)agent loginStatus:(BOOL) loggedIn;

Here is the demo project. DONT FORGET TO ADD YOUR key and secret!!
FacebookAgentTest

Tagged with:
 
  • dev

    Hello. I tried the example, the publish feed works fine and when using the image url I see the image on the facebook wall as expected. great!

    But if I run this code :

    NSData * myData = UIImageJPEGRepresentation(imageView.image,1);
    [fbAgent uploadPhotoAsData:myData withCaption:@"a caption" toAlbum:@"an album"];

    The application crashes after I have logged in to facebook with this in the console :

    2010-01-21 18:14:13.997 facebookExperiments[4520:207] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘*** -[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object’
    2010-01-21 18:14:13.999 facebookExperiments[4520:207] Stack: (
    29402203, etc etc

    I have an image in my imageView, the code is run by a button press in a view controller.

    I also tried it with UIImagePNGRepresentation in case the data is required in that format, with the same result.

    Am I doing something wrong?

  • dev

    Hello. I tried the example, the publish feed works fine and when using the image url I see the image on the facebook wall as expected. great!

    But if I run this code :

    NSData * myData = UIImageJPEGRepresentation(imageView.image,1);
    [fbAgent uploadPhotoAsData:myData withCaption:@"a caption" toAlbum:@"an album"];

    The application crashes after I have logged in to facebook with this in the console :

    2010-01-21 18:14:13.997 facebookExperiments[4520:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'
    2010-01-21 18:14:13.999 facebookExperiments[4520:207] Stack: (
    29402203, etc etc

    I have an image in my imageView, the code is run by a button press in a view controller.

    I also tried it with UIImagePNGRepresentation in case the data is required in that format, with the same result.

    Am I doing something wrong?

  • http://www.amanpages.com Shaikh Sonny Aman

    hello dev,
    sorry, it was a bug, my mistake.

    Please go to near line 202 in FacebookAgent.m. You will find a method like this:
    -(void)uploadImage{
    NSDictionary *params;

    change NSDictionary to NSMutableDictionary.

    —–

    This is found and fixed by danbaumbach.

    He shared here:
    http://amanpages.com/iphone-app-development-cor

    Thanks.

  • Cam

    Great, this is really helpful so far! I like how you fit everything into just one header and one implementation file.

    Is there any way to automatically create a photo album if it doesn’t already exist? Right now, I’m getting a “Error(120) Invalid album id” response when trying to upload a photo. I’d like it to try to create a photo album called “My Drawings” and I’m not sure how to integrate this with fbAgent

  • Cam

    Nevermind, I just replaced the album name string with nil, and that worked!

    • http://www.amanpages.com/ Shaikh Sonny Aman

      thanks for using it :)

      • Jorge

        Aman, Thanks for this. I’ve been playing with the project all afternoon and would love to use this in my next app and give you proper credit. Shoot me an email to jorge AT ripprapp DOT com and let me know if there’s anything in particular you’d like to see, I can also give you some info about the app

        • http://www.amanpages.com/ Shaikh Sonny Aman

          this project is now obsolete!! facebook released an easier facebook class :)

      • farrah

        Hello Shaikh 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.

        • http://www.amanpages.com/ Shaikh Sonny Aman

          this project is now obsolete!! facebook released an easier facebook class :)

  • Cam

    Great, this is really helpful so far! I like how you fit everything into just one header and one implementation file.

    Is there any way to automatically create a photo album if it doesn't already exist? Right now, I'm getting a “Error(120) Invalid album id” response when trying to upload a photo. I'd like it to try to create a photo album called “My Drawings” and I'm not sure how to integrate this with fbAgent

  • Cam

    Nevermind, I just replaced the album name string with nil, and that worked!

  • http://www.amanpages.com Shaikh Sonny Aman

    thanks for using it :)

  • Jorge

    Aman, Thanks for this. I've been playing with the project all afternoon and would love to use this in my next app and give you proper credit. Shoot me an email to jorge AT ripprapp DOT com and let me know if there's anything in particular you'd like to see, I can also give you some info about the app

  • bunnyhero

    This looks excellent. Thanks for sharing the code.

    I have a question: what are the terms for using this code in our own projects?

    Thanks!

    • http://www.amanpages.com/ Shaikh Sonny Aman

      No terms! you can use it as your own code for any project… but I will appreciate if you fix any bug and share the link :)

      • bunnyhero

        Thanks! I will definitely share any fixes if there are any :)

  • http://claimid.com/bunnyhero bunnyhero

    This looks excellent. Thanks for sharing the code.

    I have a question: what are the terms for using this code in our own projects?

    Thanks!

  • http://www.amanpages.com Shaikh Sonny Aman

    No terms! you can use it as your own code for any project… but I will appreciate if you fix any bug and share the link :)

  • http://claimid.com/bunnyhero bunnyhero

    Thanks! I will definitely share any fixes if there are any :)

  • aaronfisher

    Great Code – working perfect within my app…

    1 question: if the user ticks ‘keep me logged in’…how long does it keep them logged in for? Or is it permenant? If so, is there a way we can give them the option to log out ?

    (This is to avoid someone posting to their wall if they, say, leave their phone laying around).

    Thanks very much

    • http://twitter.com/ColouredRobot ✔ Victor Alexander

      From my experience it seems like it keeps them logged in for the duration of the app. If they exit and return, it seems like you have to log in again but the email is saved into the username form.

  • aaronfisher

    Great Code – working perfect within my app…

    1 question: if the user ticks 'keep me logged in'…how long does it keep them logged in for? Or is it permenant? If so, is there a way we can give them the option to log out ?

    (This is to avoid someone posting to their wall if they, say, leave their phone laying around).

    Thanks very much

  • sivasankarp

    HI

    this tutorial very kind and useful to implement the application,Thanks and congrats for your work.
    i have small doubt in this ,usually you have uploading the image URL,in my case i have to upload the browsed image from the photo album.which returns me the UIImage not NSString.may i know what changes i have to do,to solve my problem.

    Thans In advance.waiting for your response.
    small suggestion to you.im very new to iphone development,can you post how to use the webservice and can you get me the same like this

    • http://www.amanpages.com/ Shaikh Sonny Aman

      while publishing a feed to facebook, you have to provide an image url which is already uploaded to some server.

      Directly uploading an image is not supported yet, AFAIK .

      I have not yet consumed any web service from iphone, if I do i will share for sure :)

      thanks.

  • sivasankarp

    HI

    this tutorial very kind and useful to implement the application,Thanks and congrats for your work.
    i have small doubt in this ,usually you have uploading the image URL,in my case i have to upload the browsed image from the photo album.which returns me the UIImage not NSString.may i know what changes i have to do,to solve my problem.

    Thans In advance.waiting for your response.
    small suggestion to you.im very new to iphone development,can you post how to use the webservice and can you get me the same like this

  • http://www.amanpages.com Shaikh Sonny Aman

    while publishing a feed to facebook, you have to provide an image url which is already uploaded to some server.

    Directly uploading an image is not supported yet, AFAIK .

    I have not yet consumed any web service from iphone, if I do i will share for sure :)

    thanks.

  • jackiehansen

    How can I add a variable in to the text? So that I can automatically have an integer that someone scored?

    • Sascha

      [NSString stringWithFormat:@"I reached a score of %i",intScore]

  • jackiehansen

    How can I add a variable in to the text? So that I can automatically have an integer that someone scored?

  • Keith

    Hey Aman,

    I’m getting a sudden error with this; can you please check this thread:
    http://www.iphonedevsdk.com/forum/iphone-sdk-development/44014-facebook-feed-problem-all-sudden.html Thanks!

  • Sascha

    Hi!

    Great work and many many thanks for sharing!
    I would like to know if there is any way to post a feed without having the Dialog coming up?

  • Sascha

    Hi!

    Great work and many many thanks for sharing!
    I would like to know if there is any way to post a feed without having the Dialog coming up?

  • Sascha

    [NSString stringWithFormat:@"I reached a score of %i",intScore]

  • hasin

    Aman bhai, user’s need to provide their username and password for the twitter app, isnt it? But what do you think about developing somethign like ping.fm – like you configure the services in your browser with a native account (via oAuth) , and then using that username and password you can just loginto your native iphone apps (NSMutableURL) and publish the status :)

    • http://www.amanpages.com/ Shaikh Sonny Aman

      sounds interesting… need to talk in more details. thanks.

  • hasin

    Aman bhai, user's need to provide their username and password for the twitter app, isnt it? But what do you think about developing somethign like ping.fm – like you configure the services in your browser with a native account (via oAuth) , and then using that username and password you can just loginto your native iphone apps (NSMutableURL) and publish the status :)

  • http://www.amanpages.com Shaikh Sonny Aman

    sounds interesting… need to talk in more details. thanks.

  • Phios

    Hi and thanks for the great help!

    One question; in a multiview application, if I want to use Facebook functionality in different parts of my app (login in the first view, upload a pic in the second and change status in the third) how shall I use the fbAgent? Is it ok to create it in the app delegate and then access it from the other views of my application?

    • http://www.amanpages.com/ Shaikh Sonny Aman

      not sure.. may be it can be done… if you can plz share how you did it :)

      thanks.. waiting for you reply…..

      • Phios

        I’m afraid I can’t get it working right. What do you think is the best place to put the facebookAgent object? In the app delegate or in the root view controller? if it is in the root view controller, is there a way to retrieve the facebookAgent from its subviews..?

        I’m afraid I’m not ready for that kind of stuff yet :)

    • CarBoyCam

      I reckon that’s possible :)

      e.g. [appDelegate.fbAgent login]; or whatever.

      • http://www.amanpages.com/ Shaikh Sonny Aman

        Great! I will really appreciate if you share the solution.

        Thanks.

        Aman
        Sr. Software Engineer
        PlayDom

        • CarBoyCam

          I think you’d have to import your App Delegate.h file (#import “YourAppDelegate.h”), after setting up fbAgent in your delegate of course.

          Then declare your app delegate in your view’s .m file like so:

          YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];

          Then when you want to update the status etc. do this:

          [appDelegate.fbAgent setStatus:@"appDelegate FTW!"];

          That might work. Haven’t tested it myself.

          • http://www.amanpages.com/ Shaikh Sonny Aman

            yea,,, that can be done.. but actually I was talking about
            publishing/linking a URL with status using facebook connect.


            Aman
            Sr. Software Engineer
            PlayDom

          • Phios

            So, I’m trying this out now.
            In my app delegate .m file, and in the application:didFinishLaunchingWithOptions I allocate the FacebookAgent object. I have never touched this file before, so I’m not sure if this is ok or terribly wrong..
            However I have access through appDelegate.fbAgent to all my other views – now I’m testing if login, logout, posting etc works as it should.

  • Phios

    Hi and thanks for the great help!

    One question; in a multiview application, if I want to use Facebook functionality in different parts of my app (login in the first view, upload a pic in the second and change status in the third) how shall I use the fbAgent? Is it ok to create it in the app delegate and then access it from the other views of my application?

  • http://www.amanpages.com Shaikh Sonny Aman

    not sure.. may be it can be done… if you can plz share how you did it :)

    thanks.. waiting for you reply…..

  • CarBoyCam

    Hey, I’m using your FacebookAgent class in my App (PlayStation.News) but I’m having one, relatively major problem.

    When I use the code:

    [fbAgent publishFeedWithName:… blah blah

    I can’t seem to get ANY linkurl string to work. It posts to my Facebook wall absolutely fine, but no hyperlink to lead the user to the news story posted…

    Contact me at carboycam AT gmail DOT com

    Thanks!

    • Missoula

      Did you ever get this to work? It won’t work for me either.

  • CarBoyCam

    Hey, I'm using your FacebookAgent class in my App (PlayStation.News) but I'm having one, relatively major problem.

    When I use the code:

    [fbAgent publishFeedWithName:... blah blah

    I can't seem to get ANY linkurl string to work. It posts to my Facebook wall absolutely fine, but no hyperlink to lead the user to the news story posted…

    Contact me at carboycam AT gmail DOT com

    Thanks!

  • CarBoyCam

    I reckon that's possible :)

    e.g. [appDelegate.fbAgent login]; or whatever.

  • http://www.amanpages.com Shaikh Sonny Aman

    Great! I will really appreciate if you share the solution.

    Thanks.

    Aman
    Sr. Software Engineer
    PlayDom

  • CarBoyCam

    I think you'd have to import your App Delegate.h file (#import “YourAppDelegate.h”), after setting up fbAgent in your delegate of course.

    Then declare your app delegate in your view's .m file like so:

    YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];

    Then when you want to update the status etc. do this:

    [appDelegate.fbAgent setStatus:@"appDelegate FTW!"];

    That might work. Haven't tested it myself.

  • http://www.amanpages.com Shaikh Sonny Aman

    yea,,, that can be done.. but actually I was talking about
    publishing/linking a URL with status using facebook connect.


    Aman
    Sr. Software Engineer
    PlayDom

  • Phios

    I'm afraid I can't get it working right. What do you think is the best place to put the facebookAgent object? In the app delegate or in the root view controller? if it is in the root view controller, is there a way to retrieve the facebookAgent from its subviews..?

    I'm afraid I'm not ready for that kind of stuff yet :)

  • Phios

    So, I'm trying this out now.
    In my app delegate .m file, and in the application:didFinishLaunchingWithOptions I allocate the FacebookAgent object. I have never touched this file before, so I'm not sure if this is ok or terribly wrong..
    However I have access through appDelegate.fbAgent to all my other views – now I'm testing if login, logout, posting etc works as it should.

  • agoodmiller

    Hi Aman,
    Great set of code here. It’s saved me a ton of work.
    The only problem I am having is with uploading pictures. I’m getting the “Error(120) Invalid album id” response when trying.
    I tried replacing the album name string with nil as someone said in the comments, but now it errs out with a “NSInvalidArgumentException” error.
    Any idea what could be the issue? This is the final piece of the puzzle to having my program final.
    Thanks for any help you can give.
    feel free to email me at aaron at 19w dot com

  • agoodmiller

    Hi Aman,
    Great set code here. It has saved me a ton of work.
    The only problem I am having is with uploading pictures. I'm getting the “Error(120) Invalid album id” response when trying.
    I tried replacing the album name string with nil as someone said in the comments, but now it errs out with a “NSInvalidArgumentException” error.
    Any idea what could be the issue? This is the final piece of the puzzle to having my program final.
    Thanks for any help you can give.

  • http://www.discovermotion.com Jeff

    Is there any way to set the message edit box contents with publishFeedWithName that appears within the “Publish Story” (FBStreamDialog) dialog.

    I need to populate the edit box with information from my app – not simply have an empty edit box.

  • http://www.discovermotion.com Jeff

    Is there any way to set the message edit box contents with publishFeedWithName that appears within the “Publish Story” (FBStreamDialog) dialog.

    I need to populate the edit box with information from my app – not simply have an empty edit box.

  • rupeshmenon

    Hi
    First of all thanks for the tutorial. It was really helpful. But I have a problem. What to do if I had to post a static data from my application as feed. ie; I dont want to enter any thing in the text box. Instead I had to pass the value from my application which should not be editted and it has to be appear in my wall and the home page of my friends. I even dont require the text box.

    Thanks & Regards
    Rupesh R Menon
    India

  • rupeshmenon

    Hi
    First of all thanks for the tutorial. It was really helpful. But I have a problem. What to do if I had to post a static data from my application as feed. ie; I dont want to enter any thing in the text box. Instead I had to pass the value from my application which should not be editted and it has to be appear in my wall and the home page of my friends. I even dont require the text box.

    Thanks & Regards
    Rupesh R Menon
    India

  • mozymac

    hello,

    How can i make the post be posted in user’s friends page?

  • mozymac

    hello,

    How can i make the post be posted in user's friends page?

  • VictorAlexander

    Hey Aman, for some reason I keep getting the following errors:

    (WARNINGS)
    * Incomplete implementation of class ‘ThirdViewController’

    * Method definition for ‘-facebookAgent:dialog:didFailWithError:’ not found

    * Class ‘ThirdViewController’ does not fully implement the ‘FacebookAgentDelegate’ protocol

    (BUILD ERROR)
    * Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    Any help? it looks exactly the same as your sample code test.

  • http://twitter.com/ColouredRobot ✔ Victor Alexander

    Hey Jeff,

    I’m not sure if we’re allowed to import text into the edit box, but we can populate information into the message. For example

    Say you want to include a user’s text form a textView, then

    Depending on where you want to put it, (i.e. caption, etc) remove the @”how are you?” (yes including the @”") and replace it with

    [NSString stringWithFormat:@"%@", textView.text]

    Hope it helps!

    -Vicc

  • VictorAlexander

    Hey Aman, for some reason I keep getting the following errors:

    (WARNINGS)
    * Incomplete implementation of class 'ThirdViewController'

    * Method definition for '-facebookAgent:dialog:didFailWithError:' not found

    * Class 'ThirdViewController' does not fully implement the 'FacebookAgentDelegate' protocol

    (BUILD ERROR)
    * Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    Any help? it looks exactly the same as your sample code test.

  • http://twitter.com/ColouredRobot ✔ Victor Alexander

    Hey Jeff,

    I'm not sure if we're allowed to import text into the edit box, but we can populate information into the message. For example

    Say you want to include a user's text form a textView, then

    Depending on where you want to put it, (i.e. caption, etc) remove the @”how are you?” (yes including the @”") and replace it with

    [NSString stringWithFormat:@"%@", textView.text]

    Hope it helps!

    -Vicc

  • http://twitter.com/ColouredRobot ✔ Victor Alexander

    From my experience it seems like it keeps them logged in for the duration of the app. If they exit and return, it seems like you have to log in again but the email is saved into the username form.

  • Russ Stinehour

    Thank you for this post and sample. I downloaded and used my app key and secret key. When I ran the app, the “Connect to Facebook” page displayed a blank page and returned. I am missing something. Shouldn’t the login for my app page appear? Can you help me?

  • Russ Stinehour

    Thank you for this post and sample. I downloaded and used my app key and secret key. When I ran the app, the “Connect to Facebook” page displayed a blank page and returned. I am missing something. Shouldn't the login for my app page appear? Can you help me?

  • http://riskinit.com jriskin

    In the login you don’t set the delegate, which means that if they aren’t connected to the Internet there won’t be an appropriate delegate message to – (void)dialog:(FBDialog*)dialog didFailWithError:(NSError*)error;

    Simple fix, dialog.delegate = self;

    e.g.

    - (void) login{
    currentAction = FacebookAgentActionLogin;

    if(shouldResumeSession){ // try to resume first
    if(! [_session resume] ){
    if(_session.isConnected){
    // Alert already logged in?
    }else{
    FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:_session] autorelease];
    dialog.delegate = self;
    [dialog show];
    }
    }
    }else {
    if(_session.isConnected){
    // Alert already logged in?
    }else{
    FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:_session] autorelease];
    dialog.delegate = self;
    [dialog show];
    }
    }
    }

  • http://riskinit.com jriskin

    In the login you don't set the delegate, which means that if they aren't connected to the Internet there won't be an appropriate delegate message to – (void)dialog:(FBDialog*)dialog didFailWithError:(NSError*)error;

    Simple fix, dialog.delegate = self;

    e.g.

    - (void) login{
    currentAction = FacebookAgentActionLogin;

    if(shouldResumeSession){ // try to resume first
    if(! [_session resume] ){
    if(_session.isConnected){
    // Alert already logged in?
    }else{
    FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:_session] autorelease];
    dialog.delegate = self;
    [dialog show];
    }
    }
    }else {
    if(_session.isConnected){
    // Alert already logged in?
    }else{
    FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:_session] autorelease];
    dialog.delegate = self;
    [dialog show];
    }
    }
    }

  • Petem

    Your FacebookAgent is just the thing. Will you be extending it further? For example, I wish to create an album by name and load pics there, also to retrieve pics from an album by name. Also, your own getAlbumList is marked TBD. Is there a future and where are you going with this?

  • Petem

    Your FacebookAgent is just the thing. Will you be extending it further? For example, I wish to create an album by name and load pics there, also to retrieve pics from an album by name. Also, your own getAlbumList is marked TBD. Is there a future and where are you going with this?

  • James

    Anyone know how to add line-breaks to the “captionText”? Neither or n seem to work.

    Thanks.

  • James

    Anyone know how to add line-breaks to the “captionText”? Neither
    or n seem to work.

    Thanks.

  • Missoula

    Did you ever get this to work? It won't work for me either.

  • http://twitter.com/thiago_peres Thiago Peres

    I tried changing the API key and secret but when I do this the facebook connect window open and closes in 1 sec. Sorry i’m a noob in this thing…

  • http://twitter.com/thiago_peres Thiago Peres

    I tried changing the API key and secret but when I do this the facebook connect window open and closes in 1 sec. Sorry i'm a noob in this thing…

  • http://www.amanpages.com/ Shaikh Sonny Aman

    This project is now obsolete since I found facebook released a great class!!
    check out here : http://github.com/facebook/facebook-ios-sdk

  • http://www.amanpages.com Shaikh Sonny Aman

    This project is now obsolete since I found facebook released a great class!!
    check out here : http://github.com/facebook/facebook-ios-sdk

  • farrah

    Hello Shaikh 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.

  • http://www.amanpages.com Shaikh Sonny Aman

    this project is now obsolete!! facebook released an easier facebook class :)

  • http://www.amanpages.com Shaikh Sonny Aman

    this project is now obsolete!! facebook released an easier facebook class :)

  • ramya

    Hi,

    Gr8 tutorial!! Thanks.I implemented the same everything works like a charm.But i want to publish data which is selected from table ie(a user wants to share details in page which is in form of table ),how do i do that ,i tried a lot of things ,nothing seems to work ..

    Thanks.

  • ramya

    Hi,

    Gr8 tutorial!! Thanks.I implemented the same everything works like a charm.But i want to publish data which is selected from table ie(a user wants to share details in page which is in form of table ),how do i do that ,i tried a lot of things ,nothing seems to work ..

    Thanks.

  • adagio

    HI!
    This tutorial is fantactic! thanks!

    I have a problem, this is my error:

    2010-12-02 14:09:02.014 Bib[12513:207] -[pintarIpadViewController facebookAgent:photoUploaded:]: unrecognized selector sent to instance 0x4d2c7e0

    2010-12-02 14:09:02.016 Bib[12513:207] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[pintarIpadViewController facebookAgent:photoUploaded:]: unrecognized selector sent to instance 0x4d2c7e0′

    The application is correct, upload my picture on facebook, but later it’s broken.

    am I doing something wrong? tranks!

  • adagio

    HI!
    This tutorial is fantactic! thanks!

    I have a problem, this is my error:

    2010-12-02 14:09:02.014 Bib[12513:207] -[pintarIpadViewController facebookAgent:photoUploaded:]: unrecognized selector sent to instance 0x4d2c7e0

    2010-12-02 14:09:02.016 Bib[12513:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[pintarIpadViewController facebookAgent:photoUploaded:]: unrecognized selector sent to instance 0x4d2c7e0'

    The application is correct, upload my picture on facebook, but later it's broken.

    am I doing something wrong? tranks!

  • SSH

    How to use action link in ‘POST’ graph api, am failing in it even after using ‘actions’ argument.

  • SSH

    How to use action link in 'POST' graph api, am failing in it even after using 'actions' argument.

  • Haseeb

    hi …
    i done done all .. im getting the point where login popups appear ….
    but when i enter username and password… it stuck by error …

    *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[GameOverLayer facebookAgent:loginStatus:]: unrecognized selector sent to instance 0xc0c5f90′

    • http://www.amanpages.com/ Shaikh Sonny Aman

      Hello Haseeb, thank you for visiting this blog and trying the utility. But now, Facebook release Facebook graph api for objective-c which is recommended to use and that really awesome!

      • Haseeb

        thanx man … so ll u help me out wht to do at this ?

        • Haseeb

          give me idea .. which mistake i am doing ..

          -[GameOverLayer facebookAgent:loginStatus:]: unrecognized selector sent to instance 0xc1356c0

          not getting where im doing mistake … can u give me you email id ?

          • Haseeb

            love man just done it .. GOD bless u ever :

  • Haseeb

    hi …
    i done done all .. im getting the point where login popups appear ….
    but when i enter username and password… it stuck by error …

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GameOverLayer facebookAgent:loginStatus:]: unrecognized selector sent to instance 0xc0c5f90'

  • Shaikh Sonny Aman

    Hello Haseeb, thank you for visiting this blog and trying the utility. But now, Facebook release Facebook graph api for objective-c which is recommended to use and that really awesome!

  • Haseeb

    thanx man … so ll u help me out wht to do at this ?

  • Haseeb

    give me idea .. which mistake i am doing ..

    -[GameOverLayer facebookAgent:loginStatus:]: unrecognized selector sent to instance 0xc1356c0

    not getting where im doing mistake … can u give me you email id ?

  • Haseeb

    love man just done it .. GOD bless u ever :

  • Andreas

    After the FacebookAgent integration the posts are shown on the user’s own pinboard but they are not visible for other users when they login. Therefore it has no viral effect. Can anyone explain me why?

  • Andreas

    After the FacebookAgent integration the posts are shown on the user's own pinboard but they are not visible for other users when they login. Therefore it has no viral effect. Can anyone explain me why?

  • Hipark

    How can I close this facebook dialog in my app?
    I don’t know why you did hide the button..
    How can I show the close icon explicitly in the dialog?

    (Thank you for your brilliant source code.!! )

    • http://www.amanpages.com/ Shaikh Sonny Aman

      Thanks!
      But this code is obsolete now and not maintained anymore.

       Please use Facebook Graph api.

  • Hipark

    How can I close this facebook dialog in my app?
    I don't know why you did hide the button..
    How can I show the close icon explicitly in the dialog?

    (Thank you for your brilliant source code.!! )

  • http://www.amanpages.com Shaikh Sonny Aman

    Thanks!
    But this code is obsolete now and not maintained anymore.

     Please use Facebook Graph api.

  • TimelineStudios

    Your method of using FB integration is brilliant, i really like it and couldn’t follow the developers feeds on FB so this was great, i have used it in an app for my business the apps called “TimelineStudiosApp” just a basic utility app, i will release this in an update around september 011 thank you for posting..

    • http://www.amanpages.com/ Shaikh Sonny Aman

      Thanks for your comment! its really nice :)

      All the best and happy development!

  • TimelineStudios

    Your method of using FB integration is brilliant, i really like it and couldn't follow the developers feeds on FB so this was great, i have used it in an app for my business the apps called “TimelineStudiosApp” just a basic utility app, i will release this in an update around september 011 thank you for posting..

  • http://www.amanpages.com Shaikh Sonny Aman

    Thanks for your comment! its really nice :)

    All the best and happy development!

  • Saurman

    is there any way to publish photo with this lib to other’s wall or album?

  • Saurman

    is there any way to publish photo with this lib to other's wall or album?

  • Sreeram20

    Hi, thanks for tutorials. 
              Is there any way to go inside the profile page after entering the comment? Thanks in advance,

  • Sreeram20

    Hi, thanks for tutorials. 
              Is there any way to go inside the profile page after entering the comment? Thanks in advance,

  • Drsarang

    Is this still live? Your “obsolete” message is confusing. Is the entire article obsolete? If not, can you provide a link to the sample project?

    • http://www.amanpages.com/ Shaikh Sonny Aman

      yea, unfortunately the entire project is not maintained anymore :(

  • Drsarang

    Is this still live? Your “obsolete” message is confusing. Is the entire article obsolete? If not, can you provide a link to the sample project?

  • http://www.amanpages.com Shaikh Sonny Aman

    yea, unfortunately the entire project is not maintained anymore :(

  • Velraj

    Hi i want to get my friend names from Facebook  in a table view when i click a botton.can you help me out

  • Velraj

    Hi i want to get my friend names from Facebook  in a table view when i click a botton.can you help me out

  • http://www.tatvasoft.com/software-development-technology/iphone-developer.asp Jose Phabbott

    I followed the method as mentioned in your tutorial  and was successfully able to connect to my iPhone in few minutes. It’s quite easy to get around facebook through with my iPhone now.

  • http://www.tatvasoft.com/software-development-technology/iphone-developer.asp Jose Phabbott

    I followed the method as mentioned in your tutorial  and was successfully able to connect to my iPhone in few minutes. It's quite easy to get around facebook through with my iPhone now.

  • Shraddha Hattimare28

    i use facebook agent in my iphone app but login dialog is not appeared.  Any thing is remaing to add?

  • Shraddha Hattimare28

    i use facebook agent in my iphone app but login dialog is not appeared.  Any thing is remaing to add?

  • http://www.authorstream.com/Presentation/brucevelasquez-1426451-custom-software-development-in-london/ Benjamin Small

    Thanks for sharing this post to us. I would love to share this one to most of my workmates and hear their opinions.

  • http://www.authorstream.com/Presentation/brucevelasquez-1426451-custom-software-development-in-london/ Benjamin Small

    Thanks for sharing this post to us. I would love to share this one to most of my workmates and hear their opinions.

  • http://www.edocr.com/doc/39128/software-development-services-india Bruce Wells

    Your post is so interesting. and it is more useful and helpful for me. Thanks for share this valuable post.

  • http://www.edocr.com/doc/39128/software-development-services-india Bruce Wells

    Your post is so interesting. and it is more useful and helpful for me. Thanks for share this valuable post.