Android Facebook Integration


Okay, I found this a little (but only a little) tougher than integrating Twitter (with Twitter4J library) in your Android applications, but this is how it works:

  • Download the Facebook Android SDK from https://github.com/facebook
  • Extract the zip file.
  • Inside it, there is a folder called 'Facebook' . Its the SDK reference we'll be using.
  • Open up Eclipse and 'Create a new project from existing source' (I hope you know how to do it, if not, add a comment in the end), and select the Facebook SDK folder you just extracted, as the source.
  • Remember, this is just a reference project, thus you cant get an APK out of it.
  • Now create your new project.
  • Right click on your project>Properties>Android>Library
  • Select the above imported Facebook SDK as the library
  • Done, now look at the sample project I have here. It updates your facebook status after asking for login.
(sample project: https://github.com/Sheikh-Aman/Android_Samples/tree/master/3.%20FacebookExample-StatusUpdate)

There are some more IMPORTANT steps to take which are discussed here in detail. Do read them to understand what my project does. Though this sample project works, but that's because I followed all those steps.

Since its a very short and quick post, If you face any problem at any level, just ping me.

11 comments:

bittu said...

Really unbelievable step you provided thanks.

bittu said...

hey how to access registration information of login user

Shraddha said...

Hi bittu,
Its very easy.

The following link may help you out in doing so:http://developers.facebook.com/docs/reference/api/

Try using facebook-android-sdk from github. It works fine.

Shraddha said...

sample example - https://github.com/facebook/facebook-android-sdk

Aman Alam said...

@Shraddha facebook-android-sdk is what I have used.
still, thanks for driving people off :P

@bittu there's an array in my example where you specify which information of the user you need to pull. specify the info that you need to access there.

VĂ©rocs said...

hello
can you help me?
i read your article, but i cant solve this facebook problem. i write the program, but just the facebook picture comes and the loading after, and then dissapear.
what's wrong?
please help me.

thank you in advance.

Aman Alam said...

@Verocs: mail me your issue's screenshot at sheikh.aman.alam@gmail.com and lets solve it.

Shanmugam said...

Hey I implemented Facebook Sdk example, i succeded in that.
But my doubt is if i want to use only update status using Facebook SDK how can i do it?
Please help me out

Megha Sanghvi said...

hi i implement the facebook same as you mentioned but i get the following error .
Key message expected byte[] but value was a java.lang.String. The default value was returned.
if(mFacebook.isSessionValid())
{
Bundle parameters = new Bundle();
parameters.putString("message", mes);
try {
String response = mFacebook.request("me/feed", parameters,"POST");
System.out.println(response);
} catch (IOException e) {
e.printStackTrace();
}
}

Aman Alam said...

@Megha Hmm.. Looks like something's got changed!
Okay, I'll have to look at it again, but that can only be done after 8-9 days sorry for the delay! :)

Hani said...

I am unable to get the project provided in the link "facebook status update. From where can i get the code?