Iphone facebook connect simple integration and exampleYesterday I shared my
helper class on paginating data.
Today I will share how I use facebook connect to use in iPhone apps.
Problem of the approach described in facebook conenct website:
1. need to change the project settings include path
2. need to write lots of code to show login prompt, publish code, ask permission , update status etc.
Though these does not seem to be problematic but it really kills time if you are developing quite a few apps and integrating facebook connect into them.
I just encapsulated all the reusable code into a single class and a protocol for required callbacks like what should be done if logged in/out, facebook username fetched by query etc.
For example, say I want to update status.
1. first I need to write code to show login prompt
2. then i need to write code to show permission dialog
3. and then i need to write the code to update user facebook status.
but using facebook agent it is just one line of code!
// fbAgent is an instacne of FacebookAgent
[fbAgent setStatus:@\"My new status\"]
for publishing feed there are many methods, one is:
/**
* 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;
FacebookAgent will check if the user is logged in, if not it will show the login in prompt.
Once logged in, it will show the permission dialog if not given permission earlier.
Then it will update the user status.
I can also define some delegate method to work on some events like:
/**
* This method is called if after login or logout
*/
- (void) facebookAgent:(FacebookAgent*)agent loginStatus:(BOOL) loggedIn;
/**
* Must define this method if uploadPhoto is called
*
* This method is called after photo is uploaded
*/
- (void) facebookAgent:(FacebookAgent*)agent photoUploaded:(NSString*) pid;
....
//etc
More detail with sample code is available
in this page:
All code is free to use without any obligation even for closed source commercial projects but I will appreciate if you let me know.
**** UPDATE 8 Jan 2010 ***New functionality added.
Now it is possible to post a photo and then change the status automatically by a single call.
Basically it was scotopia's idea. Thanks.@scotopia
- (void) uploadPhotoAtURL:(NSString*)imageurl withCaption:(NSString*)captionOrNil toAlbum:(NSString*)aidOrNil;
- (void) uploadPhotoAsData:(NSData*)imagedata withCaption:(NSString*)captionOrNil toAlbum:(NSString*)aidOrNil;
/**
* Upload photo with status
*/
- (void) uploadPhoto:(NSString*)imageurl withStatus:(NSString*)status;
- (void) uploadPhotoAtURL:(NSString*)imageurl withStatus:(NSString*)status caption:(NSString*)captionOrNil toAlbum:(NSString*)aidOrNil;
- (void) uploadPhotoAsData:(NSData*)imagedata withStatus:(NSString*)status caption:(NSString*)captionOrNil toAlbum:(NSString*)aidOrNil;
/**
* Ask permission to auto approve uploaded photo and add photo to an album.
*/
- (void) askUplaoadPhotoToAlbumPermission;
iOS application development lead at MobiLab Solutions.
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
Replies
10 Detailed Steps to Submit Apps To AppStore
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeExpert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeLooks very interesting; thanks for the post! I just have a few quick questions
1) Is this already set up to test reachability type stuff or do we need to tweak that ourselves (easy, just curious)
2) Will the feed post method you have work for a situation like this:
In my app there is a user created image gallery and I would like them to be able to upload a select image to facebook and have the status update be something like:
"[uploaded pic here]: I just made this with iPhone App X"
etc.
The previous discussion on this matter lead to that this process would actually be two steps; first uploading the pic to the users unapproved gallery and then making a feed post that includes the image....would your method do it all in one shot or do similar shenanigans need to occur?
Again; thanks for the post!
[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome1. no. reachability files often come with some ad network sdk(at least the ones that i/we use for our comes), so to avoid errors its not added in the facebookagent files.
Now, if there is no net and if you've defined
this delegate method, this method will be called with loggedIn = NO.
2. No, but I really like the idea. Hope to add it soon in the FacebookAgent, it will be really handy!
There is also some other similar utility component like that I made for my personal ease like TwitterAgent(no openoath, offers login and message option using UIAlertVews with character counter), HttpPoster/Getter( easy post mixed data like string, int, image, option to fetch dictionary, array etc from json web data), RatingAgent, CommentAgent etc.
But they are yet mostly wired up in the apps.. I will soon separate them in modules and share..
Though I know these are very trivial, no extra coding expertise needed... just need some time... even though it may come into anyone's help... at least mine :)
Thanks for you reply!
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHey! I've just updated the facebookagent. Now it has few more functions:
So now you can do what you wanted i.e. post a photo and then change the status automatically by a single call!
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeBurstly is the only open and free ad management platform for iPhone app developers.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomedoesn't do exactly what I was suggesting earlier. The status update and the picture upload do happen in one call, yes, but they are unrelated. What would really be awesome is to have the status update link to the uploaded image as I was stating above.
Perhaps have something where the photoUploaded callback triggers the status update using the pID to somehow include the image or some such? Fiddling with it now but still new to this facebook jazz.
[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeyea, resume is not there. thanks.
to get the photo url from id you need to run a fql which is not also in FacebookAgent now.
If you implement I will appreciate if you share :)
http://wiki.developers.facebook.com/index.php/Photos.get
btw, when a user adds a photo, that is published as feed to the wall by facebook itself.
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeMore here and here.
Hope it helps for now.
I will add to to FacebookAgent soon, if you update the class by this time, please share :)
Thanks
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks for your support.
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeDownload the code form previous location.
:)
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSo this can not take imageWithData right from the app correct; so the image must first be uploaded using previous techniques and then linked by the url? (I am at my day job right now and not on a mac so I'm currently flying blind).
Thanks for all your hard work so far!
[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI am under lees pressure at my job at the moment ... just utilizing my time by modularizing the scattered code :D
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome1) Do a regular uploadImage (not to feed or anything or else it will be a "double wammy"
2) In the imageUploaded (or whatever) callback do a fql call using the returned pID to get the URL of the image just uploaded
3) Use that url in the method you just added
This will produce a single feed post like the farmville one above with the uploaded image in it, correct? Thanks!
[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomealternatively, you can also upload an image to your own server and use the image url to publish the feed. it will also help in another situation( if ever occurs/possible), have an admin panel to delete unwanted/BAD images (which often become a serious issue for photo uploading apps).
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomebut, then the photos will be added to an album named after the facebook app name for each user... and AFAIK an album has an maximum photo limit of 200 or something, right?
UPDATE:
just now came to know that FB withdrew album photo limit!!!
http://www.allfacebook.com/2009/01/facebook-album-uploads/
Expert in Java/Spring/OSGi, iOS app development.
Enthusiastic C/C++, PHP, Cocoa Mac App developer.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome1. When the image gets uploaded it automatically goes to the feed as well; so with that and the deliberate feed post it is a "double whammy" that might be annoying; is there anyway to make the image upload go ninja style; so that it doesn't trigger a feed post?
2. Is there anyway to make it so the user is not prompted to insert some text before the feed publish? I tried setting the userPrompt field to nil but it just seemed to default it to "what's on your mind" with the the text area still there. I'm reading the docs now but its confusing: I think some auto_publish bool must be set to true somewhere and the app must have "extended permission"
Edit: I figured this one out: the "preview" value must be set to 0 in the feedDialogue; for some reason permissions didn't need to to be asked for publish stream; weird...
Also one suggestion: on the photo upload methods you have one of the parameters is captionOrNil; this is a little misleading as a nil causes a crash; perhaps a captionOrEmptyString ?
[IMG]http://www.omegasoftweb.com/omega/omegasoftIconBanner.png[/IMG]
Aura Trainer | <a href="http://bi
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome