Facebook SDK – Posting to User News Feed

  • Twitter
  • Facebook
  • Digg
  • Reddit
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
March 28th, 2011 Posted by: - posted under:Tutorials


Hello, I’m Andy Yanok (Twitter) and I recently finished working on Friended for Facebook.  Many applications use Facebook for posting content from their respective applications, there could be infinite items that a developer would like to post to users feeds whilst using their applications but today we will be focusing on posting a link to a users feed.

In order to get started using the Facebook SDK & API’s you will need to download the latest copy of the Facebook SDK for iOS.  For further reference to using the Graph and FQL API’s you can refer to Facebook’s API documentation.  As I am sure you are used to using the great documentation provided by Apple for developing your iOS applications, but you may find the Facebook API documentation to not be so great.

In order to integrate Facebook into your app you will need to create an application on www.facebook.com/developers.  After creating the application you will be provided with keys needed for accessing the API’s. There are some nice features to integrating Facebook into your application such as seeing how many people “Like” your application, and statistics about the usage of your application.

In this tutorial we will be creating a simple Facebook news feed posting application with the following features/functionality.

  • Facebook API / SDK Request Wrapper
  • News feed post class
  • Simple UI to test the code

Getting Started:

Before you can begin writing code there are a few setup steps you will need to perform to setup access to the Facebook API.

First you will need to logon to www.facebook.com/developers, and create an application.  For this tutorial you can use the keys provided in the sample project. Once you have created an application the developer page Facebook will provide you with the keys needed .

Secondly, you will need to download the source for the Facebook SDK https://github.com/facebook/facebook-ios-sdk.  You may also pull the SDK source out of the sample project provided.  Included with the Facebook SDK are JSON parsing libraries, the Facebook SDK uses these libraries to parse the incoming data from their servers. Once this is done you can start to code!

Within your xCode project you will need to include the Facebook SDK folder and the JSON parsing Library folder.

Creating FBRequestWrapper class:
This class can be used to make GET and POST requests to the API. I like using a singleton class for this, obviously whilst writing Friended we have to make many requests and this proved to be the best method for what we needed. This is a singleton class that will handle all the requests for accessing the Facebook API.

#import "Facebook.h"
 
#define FB_APP_ID @"197366800287642"
#define FB_API_KEY @"3269fff9ef3b6fc13255e670ebb44c4d"
#define FB_APP_SECRET @"d038b12cc8632865952f69722fe26393"
 
@interface FBRequestWrapper : NSObject
{
	Facebook *facebook;
	BOOL isLoggedIn;
}
 
@property (nonatomic, assign) BOOL isLoggedIn;
 
+ (id) defaultManager;
- (void) setIsLoggedIn:(BOOL) _loggedIn;
- (void) FBSessionBegin:(id) _delegate;
- (void) FBLogout;
- (void) getFBRequestWithGraphPath:(NSString*) _path andDelegate:(id) _delegate;
- (void) sendFBRequestWithGraphPath:(NSString*) _path params:(NSMutableDictionary*) _params andDelegate:(id) _delegate;
 
@end

In the FBRequestWrapper.h file you will need to define the keys provided when you created your application on the Facebook Developer site.

FB_APP_ID, FB_API_KEY, FB_APP_SECRET

We will be creating two class variables, one for the Facebook SDK class, and a logged in Boolean variable which holds the status of being logged in.

Moving on to the Implementation of the FBRequestWrapper. FBSessionBegin this method is being used to instantiate the facebook object if it already has not, also will be connect the application to the Facebook SDK. Within this method we pull out the stored values for the accessToken and expiration date. These values are stored in NSUserDefaults once a user has logged in, we store these so that we will not have to repeatedly need to request these values from Facebook.

Once we have that setup, we need to specify an Array of the permissions this application will be requesting. For this application we only need the “publish_stream” permission, for more information on other permissions you can refer to the Facebook API Reference. Once we have created this array with the requested permissions we call the facebook authorize method. We are specifying the delegate passed to this wrapper class as the call back for a success or failure to login, this will be discussed in detail later.

- (void) FBSessionBegin:(id) _delegate {
 
	if (facebook == nil) {
		facebook = [[Facebook alloc] init];
 
		NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"];
		NSDate *exp = [[NSUserDefaults standardUserDefaults] objectForKey:@"exp_date"];
 
		if (token != nil && exp != nil && [token length] > 2) {
			isLoggedIn = YES;
			facebook.accessToken = token;
            facebook.expirationDate = [NSDate distantFuture];
		} 
 
		[facebook retain];
	}
 
	NSArray * permissions = [NSArray arrayWithObjects:
							 @"publish_stream",
							 nil];
 
	//if no session is available login
	[facebook authorize:FB_APP_ID permissions:permissions delegate:_delegate];
}

Next we need to create the method that will be passing the POST requests to the Facebook API.

// Used for publishing
- (void) sendFBRequestWithGraphPath:(NSString*) _path params:(NSMutableDictionary*) _params andDelegate:(id) _delegate {
 
	if (_delegate == nil)
		_delegate = self;
 
	if (_params != nil && _path != nil) {
 
		[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
		[facebook requestWithGraphPath:_path andParams:_params andHttpMethod:@"POST" andDelegate:_delegate];
	}
}

In this method we are simply doing some validation, and sending the POST request to Facebook. The delegate passed to this method will be receiving the Pass/Fail response. This method will be used for all POST requests in the future. Other methods that are in the sample project are not contained in the scope of this tutorial.

Next we need to create the FBFeedPost class which will handle posting three different types of items to the users news feed. We will start by creating an enumeration to handle the 3 different types of posts that we will be explaining. We need three different post types, FBPostTypeStatus, FBPostTypePhoto, FBPostTypeLink. Once the enumeration has been completed we will create 5 properties in the class to be used, and create a delegate for a callback with the result of posting to Facebook.

#import "FBRequestWrapper.h"
 
@protocol FBFeedPostDelegate;
 
typedef enum {
  FBPostTypeStatus = 0,
  FBPostTypePhoto = 1,
  FBPostTypeLink = 2
} FBPostType;
 
@interface FBFeedPost : NSObject
{
	NSString *url;
	NSString *message;
	NSString *caption;
	UIImage *image;
	FBPostType postType;
 
	id  delegate;
}
 
@property (nonatomic, assign) FBPostType postType;
@property (nonatomic, retain) NSString *url;
@property (nonatomic, retain) NSString *message;
@property (nonatomic, retain) NSString *caption;
@property (nonatomic, retain) UIImage *image;
 
@property (nonatomic, assign) id  delegate;
 
- (id) initWithLinkPath:(NSString*) _url caption:(NSString*) _caption;
- (id) initWithPostMessage:(NSString*) _message;
- (id) initWithPhoto:(UIImage*) _image name:(NSString*) _name;
- (void) publishPostWithDelegate:(id) _delegate;
 
@end
 
@protocol FBFeedPostDelegate
@required
- (void) failedToPublishPost:(FBFeedPost*) _post;
- (void) finishedPublishingPost:(FBFeedPost*) _post;
@end

This class will be specifically be used for posting three different types of posts to your news feed. In this case I have created three different initialization methods for the different posts.

- (id) initWithLinkPath:(NSString*) _url caption:(NSString*) _caption {
	self = [super init];
	if (self) {
		postType = FBPostTypeLink;
		url = [_url retain];
		caption = [_caption retain];
	}
	return self;
}
 
- (id) initWithPostMessage:(NSString*) _message {
	self = [super init];
	if (self) {
		postType = FBPostTypeStatus;
		message = [_message retain];
	}
	return self;
}
 
- (id) initWithPhoto:(UIImage*) _image name:(NSString*) _name {
	self = [super init];
	if (self) {
		postType = FBPostTypePhoto;
		image = [_image retain];
		caption = [_image retain];
	}
	return self;
}

The meat and potatoes of this class is contained within the publishPostWithDelegate method.

We pass in the delegate that will be handling the response we receive from the FBRequrestWrapper class. From there we will be checking whether we are currently logged in to Facebook, if not make the Request to login via the FBRequestWrapper. If this is the first time the application is being ran for the users login they will be prompted to allow access to post to the users feed. Once the user has allowed access for the application to access the users feed they will no longer be prompted again to allow access.

Once logged in, we determine which post type we will be sending to the users feed. Each of the three different post types require specific parameters to be passed to Facebook via a dictionary.

Once the proper parameters have been set simply call:

 [[FBRequestWrapper defaultManager] sendFBRequestWithGraphPath:graphPath params:params andDelegate:self];

Whilst making the request we will be passing the delegate of the FBRequestWrapper as self, not the previously passed in delegate for the FBFeedPost class. We do this in order to handle deallocating the FBFeedPost instance after a failure or success message has been passed back from the Facebook API.

Within the FBFeedPost class we are implementing the Facebook SDK call back methods.

- (void) publishPostWithDelegate:(id) _delegate {
 
	//store the delegate incase the user needs to login
	self.delegate = _delegate;
 
	// if the user is not currently logged in begin the session
	BOOL loggedIn = [[FBRequestWrapper defaultManager] isLoggedIn];
	if (!loggedIn) {
		[[FBRequestWrapper defaultManager] FBSessionBegin:self];
	}
	else {
		NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
 
		//Need to provide POST parameters to the Facebook SDK for the specific post type
		NSString *graphPath = @"me/feed";
 
		switch (postType) {
			case FBPostTypeLink:
			{
				[params setObject:@"link" forKey:@"type"];
				[params setObject:self.url forKey:@"link"];
				[params setObject:self.caption forKey:@"description"];
				break;
			}
			case FBPostTypeStatus:
			{
				[params setObject:@"status" forKey:@"type"];
				[params setObject:self.message forKey:@"message"];
				break;
			}
			case FBPostTypePhoto:
			{
				graphPath = @"me/photos";
				[params setObject:self.image forKey:@"source"];
				[params setObject:self.caption forKey:@"message"];
				break;
			}
			default:
				break;
		}
 
		[[FBRequestWrapper defaultManager] sendFBRequestWithGraphPath:graphPath params:params andDelegate:self];
	}
}
 
#pragma mark -
#pragma mark FacebookSessionDelegate
 
- (void)fbDidLogin {
	[[FBRequestWrapper defaultManager] setIsLoggedIn:YES];
 
	//after the user is logged in try to publish the post
	[self publishPostWithDelegate:self.delegate];
}
 
- (void)fbDidNotLogin:(BOOL)cancelled {
	[[FBRequestWrapper defaultManager] setIsLoggedIn:NO];
 
}
 
#pragma mark -
#pragma mark FBRequestDelegate
 
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
	[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
	NSLog(@"ResponseFailed: %@", error);
 
	if ([self.delegate respondsToSelector:@selector(failedToPublishPost:)])
		[self.delegate failedToPublishPost:self];
}
 
- (void)request:(FBRequest *)request didLoad:(id)result {
	[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
	NSLog(@"Parsed Response: %@", result);
 
	if ([self.delegate respondsToSelector:@selector(finishedPublishingPost:)])
		[self.delegate finishedPublishingPost:self];
}

Once either Facebook has returned a success message or failure we will call the FBFeedPost’s corresponding delegate methods with a parameter of self so we can handle the memory management necessary after we have finished posting to the users feed.

Now that this class is implemented we can easily use this class! Within the sample project you can see all three post type examples. To Post a status to your feed, all you need to implement are the FBFeedPost Delegate methods and creating the request.

- (IBAction) btnPostPress:(id) sender {
 
	[self.txtView resignFirstResponder];
 
	//we will release this object when it is finished posting
	FBFeedPost *post = [[FBFeedPost alloc] initWithPostMessage:self.txtView.text];
	[post publishPostWithDelegate:self];
 
	IFNNotificationDisplay *display = [[IFNNotificationDisplay alloc] init];
	display.type = NotificationDisplayTypeLoading;
	display.tag = NOTIFICATION_DISPLAY_TAG;
	[display setNotificationText:@"Posting Status..."];
	[display displayInView:self.view atCenter:CGPointMake(self.view.center.x, self.view.center.y-100.0) withInterval:0.0];
	[display release];
}
 
#pragma mark -
#pragma mark FBFeedPostDelegate
 
- (void) failedToPublishPost:(FBFeedPost*) _post {
 
	UIView *dv = [self.view viewWithTag:NOTIFICATION_DISPLAY_TAG];
	[dv removeFromSuperview];
 
	IFNNotificationDisplay *display = [[IFNNotificationDisplay alloc] init];
	display.type = NotificationDisplayTypeText;
	[display setNotificationText:@"Failed To Post"];
	[display displayInView:self.view atCenter:CGPointMake(self.view.center.x, self.view.center.y-100.0) withInterval:1.5];
	[display release];
 
	//release the alloc'd post
	[_post release];
}
 
- (void) finishedPublishingPost:(FBFeedPost*) _post {
 
	UIView *dv = [self.view viewWithTag:NOTIFICATION_DISPLAY_TAG];
	[dv removeFromSuperview];
 
	IFNNotificationDisplay *display = [[IFNNotificationDisplay alloc] init];
	display.type = NotificationDisplayTypeText;
	[display setNotificationText:@"Finished Posting"];
	[display displayInView:self.view atCenter:CGPointMake(self.view.center.x, self.view.center.y-100.0) withInterval:1.5];
	[display release];
 
	//release the alloc'd post
	[_post release];
}

Posting to Facebook is easy as that! You can find all the code from this tutorial in the sample project .

  • Anonymous

    Thanks for sharing the code. It solved me a couple of issues.
    But why don’t use the SSO feature? Or am I missing it?

  • gnuchu

    Don’t think you should be posting your own API keys here. What’s to stop anyone else using them?

  • ayanok

    I Created those API keys for this example, so people can use them if they wish.

  • Ayanok

    If you are saying SSO as in single sign on, that would be making the login to use the application go into the background and either use safari or the default Facebook app? We didn’t wan’t it to leave the application to login.

  • Ayanok

    I created those API keys for the example, anyone can use them if they wish.

  • Anonymous

    Yep. Well in fact it asks for permissions, not login, but yeah, we don’t like it either that the app go into background.

  • Brandon

    Great tutorial, I was able to easily integrate it into my app. I am only using the post photo option. Quick question though. I noticed in my testing that when I post a photo it works perfect the first, second, and third time and so on, but if I remove the post by logging into my facebook account and clicking the little x remove button I can no longer get the posts to show up. It’s like removing the posts blocks the app from posting. I tried logging out and back in, removing the applications permissions and letting it ask me for permission to post again, nothing seems to allow me to post again. Any thoughts?

    I tested it with the sample code above and the same issue happens with my account. I tried it with the post link option and that does not have the same issue. Seems to be only with posting the photo.

    To recreate use the sample code above… post image. Then log into facebook and remove the post (only click remove, not revoke or remove app) Now if you try and post the image again it will say it posted, but never show up in facebook.

  • Ayanok

    Yeah basically just changed some code in the Facebook sdk to bypass those two methods. Even though multitasking is great it is still annying to leave the app.

  • http://www.mobigyaan.com Mashhood Ahmad

    thanks for sharing…really cool it looks..

  • http://twitter.com/toliver182 toliver182

    Wow this is great, thank you very much. Is there away with the above code to add a description to the image? so you can include the itunes link for the app.? Thanks

  • http://twitter.com/toliver182 toliver182

    also i notice there is nothing to hand if the user presses cancel, can you point me in the right direction to cancel everything if they do? many thanks.

  • Ayanok

    - (void)fbDidNotLogin:(BOOL)cancelled; is called when the user cancels the Login Dialog. This call is part of the FBSessionDelegate Protocol.

  • http://twitter.com/DavidCasanellas David Casanellas

    Hello to everyone, I am developing an application for iOS using the Facebook SDK and I have some trouble once I’ve implemeted the Single-Sign-On. The problem is that I don’t understand at all how to call the Graph API (methods like the few next)

    //get information about the currently logged in user
    [facebook requestWithGraphPath:@"me" andDelegate:self];

    //get the logged-in user’s friends
    [facebook requestWithGraphPath:@"me/friends" andDelegate:self];

    //call a legacy REST API
    NSMutableDictionary* params = [NSMutableDictionary
    dictionaryWithObjectsAndKeys: @"4", @"uids", @"name", @"fields", nil];

    [facebook requestWithMethodName: @"users.getInfo"
    andParams: params andHttpMethod: @"GET" andDelegate: self];

    So I am stuck in here. I appreciate very much some help!

    Thanks a lot, David.

  • http://twitter.com/toliver182 toliver182

    thanks, im still a little confused how i can pass this back to my view to remove the iffnnotification from the view?

  • Brandon

    I’m having the same issue. If you cancel the login the notification wheel spins forever.

    Looking through the code I thought I could figure it out, but I couldn’t figure out how to get the isLoggedIn BOOL passed into my .m file. Everything I tried didn’t pass the value with it. I also tried to add the fbDidNotLogin to my .m file but that too was not being called. I ended up just removing the notification during the upload and only show the “Posted” or “Failed” notification.

  • Monclerjacketsdx454gvcxb3

    White color is pretty appreciably synonymous with pearls but they do arrive in other eye-catching colours just like black, pink, lavender, http://www.cheapguccionlineshop.com/replica-gucci-uk.html golden and gray etc. There are 4 types of pearls plus they are freshwater, Akoya seawater, Tahitian and South seawater ones. Freshwater and akoya market extra than other styles usually for their reduce expenses and color brilliance.

  • Anonymous

    thanks for a great tutorial, you think apps like fubr use these kinda methods?

  • Rizwankhan1108

     Hello  Andy, I can’t get logged out and login  from the Facebook app , How can i do that ,this method is not called,- (void)logout:(id)delegateand also tell me about login, how can i get login page,please suggest me,

  • http://twitter.com/vulvaji vulvaji

    very helpful, can we have the tutorial for twitter as well..

  • Rashed Nizam

    This is a good tutorial but not a step by step one

  • VyacheslavK

    Really nice tutorial thank you for that. But i have a question how i can show only my feed from Facebook like you did in your application Friended for Facebook?

  • Ga

    If you could include video uploads, I would be very happy.

  • Ahsan

    Hi there, Thanks a lot for the wonderful tutorial. Works fine and good. My only problem is this : If I dont give permission to the app, it keeps saying “Posting A Link” and never stops….. Shouldnt it reach the postFailedToPublish function and do whatever is there ? It doesnt reach the particular function. Can you please tell me  if theres something more to do ?

    Thanks.

  • G. Apple

    Could you please post exactly what changes you made to the SDK?  I found a couple of them, but could not get this to work in my own code using what I believe to be a later SDK that included localAppID.  Even making the changes I found, I could not get it to work in my own code until I tossed the SDK and used exactly what you used here, so obviously, I missed something.  Thanks.

  • TigerSand

    I cannot get the photos to post to save my life.  I had an app that was able to do it, but in the last two months I have not been able to find a way for the photos to show up on my Facebook account.  I have tried this code along with my old code and (what seems like hundreds of) other examples and nothing seems to work.  Statuses, links, etc all work fine, but photos will not create a new album, post to my wall, or save to my account period.  Does anyone know what could be happening?

  • Ayanok

    I know facebook’s SDK is kind of buggy with logout, but there should be the Facebook access token stored to NSUserDefaults, should have to clear this out.  IE. set the default to @”", and then when the sdk tries to use this token it will fail to log in and it will pop up the login screen.

  • http://twitter.com/AndyYanok Andy Yanok

    I actually haven’t tried this as of yet, Maybe my next post will be about video uploads :)

  • http://twitter.com/AndyYanok Andy Yanok

    If you denied access, then Facebook probably returns that you don’t have permission to do such a thing.  Or something along those lines, also they could potentially  return a response saying that it failed to post to Facebook.  If I remember correctly often, for POST type calls they will return “success:1″ in this case it would probably be 0, not a failure with the call but a failure with the back end.

  • Anonymous

    I love this tutorial.  Thank you so much for breaking this down into a way that really makes a lot of sense.

    I am having issues trying to replicate posting photos to my wall, though. If I try posting using “me/feed” it doesn’t post the caption or photo – but it does post a weird empty placeholder.  If I use the path “me/photos” it successfully posts to a photo album specific to my app name – but not to my wall at all.  Any ideas what I may be missing?

  • Anonymous

    I wonder – can you show us what it would look like to incorporate this tutorial with loading basic information about the authenticated user.  For example, I’m trying to send “me” as the graph path to load my name and URL of my photo – but how would that work with this example project?

  • mkk

    Hi there, thanks for the tutorial. I have just a question for you.

    Is it possible to localize the credentials login page based on language is set on iPhone?

  • mkk

    Hi there, thanks for the tutorial. I have just a question for you.

    Is it possible to localize the credentials login page based on language is set on iPhone?

  • Byron886422

    Could you make an easy tutorial video?

    Actually I want to build an App witch could be available to write a memo and post that memo to Facebook.

  • Byron886422

    Could you make an easy tutorial video?

    Actually I want to build an App witch could be available to write a memo and post that memo to Facebook.

  • Jacomanit

    Hi,
    I’ve a cocos2D+Open Feint game and I’m trying to integrate your class.

    Step 1:
    - i drag&drop “External Framework” folder + “FBFeed+FBRequest” classes in my project

    When I compile I get this error:
    ld: duplicate symbol _FBIsDeviceIPad in /Users/alessandro/Desktop/Cocos2D – Beginner guide/Crumbers/110820 – Crumbers – v1.3 – Facebook/build/InAppTest.build/Debug-iphonesimulator/Crumbers.build/Objects-normal/i386/FBDialog-DE3695A670841D72.o and /Users/alessandro/Desktop/Cocos2D – Beginner guide/Crumbers/110820 – Crumbers – v1.3 – Facebook/build/InAppTest.build/Debug-iphonesimulator/Crumbers.build/Objects-normal/i386/FBConnectGlobal.oNot being able to solve it….any suggestions?

  • Jacomanit

    Hi,
    I’ve a cocos2D+Open Feint game and I’m trying to integrate your class.

    Step 1:
    - i drag&drop “External Framework” folder + “FBFeed+FBRequest” classes in my project

    When I compile I get this error:
    ld: duplicate symbol _FBIsDeviceIPad in /Users/alessandro/Desktop/Cocos2D – Beginner guide/Crumbers/110820 – Crumbers – v1.3 – Facebook/build/InAppTest.build/Debug-iphonesimulator/Crumbers.build/Objects-normal/i386/FBDialog-DE3695A670841D72.o and /Users/alessandro/Desktop/Cocos2D – Beginner guide/Crumbers/110820 – Crumbers – v1.3 – Facebook/build/InAppTest.build/Debug-iphonesimulator/Crumbers.build/Objects-normal/i386/FBConnectGlobal.oNot being able to solve it….any suggestions?

  • Mjellings

    I find Facebook’s documentation of the SDK to be quite lacking.  Do you have a good reference source you could direct me to?  Thanks!

  • Sanjay 6st

    Thanks for this great Tutorial
    But Actually i m facing a problem…that when i m posting a photo it will display on my FB wall but next time when i post it will go directly to my FB Album and it is not showing me any post on wall.it will directly save in album
    I can’t see another post on my wall….Please Help me

  • Snehn Kuruvilla

    hi andy.
    thanks for the tutorial.great one.

    But I am getting some issues when I am trying to integrate with my app.
    I cannot get the “post” button and the “Facebook demo” button(go back button) on the top.
    can you help..

  • Eric

    Your code looks great. I like the way you handle posting until after login is successful. With that said, I don’t see a version of authorize that takes a delegate as a parameter. As far as I know I have the latest version of the Facebook iOS SDK. Any ideas?

  • Nitin

    HI it’s awesome tutorial.So,thanks for that but i got one bug in your sample code that is you Facebook session doesn’t logout and if user close Facebook login view than after alert view for photo posting…is running.I have tried to solve this but i can’t solve this bug..hope you can help me…

    Regards,
    Nitin….

  • Nitin

    HI it’s awesome tutorial.So,thanks for that but i got one bug in your sample code that is your Facebook session doesn’t logout and if user close Facebook login view than after alert view for photo posting…is running.I have tried to solve this but i can’t solve this bug..hope you can help me…

  • Nitin

    HI it’s awesome tutorial.So,thanks for that but i got one bug in your sample code that is your Facebook session doesn’t logout and if user close Facebook login view  without login than after alert view for photo posting…is running.I have tried to solve this but i can’t solve this bug..hope you can help me…

  • http://www.facebook.com/profile.php?id=100000256210889 Anatoly Vaynshteyn

    Hi, nice and useful post.

    I have discovered one mistake in FBFeedPost method initWithPhoto.

    instead of:
    caption = [_image retain];
    should be:
    caption = [_name retain];

  • ceuur

    Hi! 

    Thank u for this tutorial.

    I have a question. In FBRequestWrapper.h file, what is FB_API_KEY? I have app_id and app_secret keys but i don’t have that. 

    Thanks.

  • http://www.facebook.com/profile.php?id=100000256210889 Anatoly Vaynshteyn

    I would recommend also add to the FBFeedPostDelegate protocol (defined in FBFeedPost.h) method like -(void)cancelLogin and call it from fbDidNotLogin (FBFeedPost.m). Very useful if the user will change his decision to login and post. Example:

    - (void)fbDidNotLogin:(BOOL)cancelled {
    [[FBRequestWrapper defaultManager] setIsLoggedIn:NO];
    [self.delegate cancelLogin];
    }

    In cancelLogin implementation you have to hide waiting hud:

    -(void)cancelLogin {
    UIView *dv = [self.view viewWithTag:NOTIFICATION_DISPLAY_TAG];
    [dv removeFromSuperview];
    }

  • http://www.facebook.com/kaustubhkushte Kaustubh Kushte

    Thanks for the tutorial :)

  • ImmaKillYou

    resolved the Xcode 4.2 warning… much thanks!

  • awesome77

    Anatoly,

    FBFeedPost doesn’t have a view, so how can you use “self.view” inside cancelLogin function?
    I got an error stating “Property of view not found on object of type “FbFeedPost”.  Any suggestions?

  • awesome77

    i think i got it…nevermind…thanks…

  • Adil Soomro

    Extremely awesome, Very Helpful and Easy as well very detailed even optimized.
    Thanks

  • Xin_ca

    Hi, I found two problems.
    The first one is already pointed out by Anatoly,
    - (id) initWithPhoto:(UIImage*) _image name:(NSString*) _name {
        self = [super init];
        if (self) {
            postType = FBPostTypePhoto;
            image = [_image retain];
            caption = [_name retain];
        }
        return self;
    }
    The caption should be got from [_name retain].

    The second one is that the newest facebook SDK has changed.
        [facebook authorize:FB_APP_ID permissions:permissions delegate:_delegate];   
    cannot be found in the SDK again.
    How should we change the code according to the latest facebook sdk?

    Thanks a lot!

  • Xin_ca

    Great post!

    ========
        //if no session is available login
        [facebook authorize:FB_APP_ID permissions:permissions delegate:_delegate];
    ========
    The above code is already outdated in the latest facebook sdk.

    How could we change to make the wrapper classes work in the newest facebook sdk code?

    Thanks a lot!

  • Littlepeculiar

    This was amazing. Exactly what I was looking. I was having tons of trouble trying to implement Facebook into my app. This cleared things up for me. I have a quick question tho, (hoping to avoid the FB documentation). Is there a way to post to someone else’s wall, someone you’re friends with of course.
    thanks.

  • Brett

    How did you fix this, I am confused?

  • Brett

    Doh!…got it now.

  • Benjamin Kong
  • Benjamin Kong

    Hi all this is an amazing tutorial. Is there a reason why i am receiving a bad signal access at the responds to selector part?
    *note : i used the facebook frameworks given by Andy. I didnt use the new Facebook Framesworks.

    - (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate {
      self.accessToken = token;
      self.expirationDate = expirationDate;
      if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogin)]) {
        [_sessionDelegate fbDidLogin];
      }
    }also, is there a reason why the new frameworks are giving problems when uploading pictures?

  • http://www.facebook.com/profile.php?id=1514357795 Cmin Ong

    great tutorial, can i ask? is that possible create an button to let user like some fb page, and then post the image in to that fb page? 

  • http://pulse.yahoo.com/_FSM5FEN2YG6XBC3MPGOCIDRUJM UE

    how to post the message to a group?

    thanks

  • http://pulse.yahoo.com/_FSM5FEN2YG6XBC3MPGOCIDRUJM UE

    how to post the message to a group?

    thanks

  • Garnik

    This is the best example. Thx

  • http://www.facebook.com/profile.php?id=31501157 Dan Brateris

    HAving trouble getting this to work with the latest Facebook sdk, some of the authorize methods are not there, any ideas?

  • Groumfy69

    Useful post, thank you!

  • HORUS793

    Hi.
    Can you please point out which changes you made?

  • http://www.facebook.com/people/Peter-Mfma/100001966099192 Peter Mfma

    I’m facing this error.

    : DevanagariSangamMN: FT_Load_Glyph failed: error 6.

blog comments powered by Disqus
canakkale canakkale canakkale balik tutma search canakkale vergi mevzuati