Android Facebook API example using FBRocket
This post is posted as per the request of many comments on Android JTwitter Example.
Now let proceed ahead with Facebook using FBrocket.
Using FB rocket we can update our facebook profile status from mobile application.
- Import the FBrocket JAR file to the eclipse project and add it to JAR libraries. Download here ( http://www.xeomax.net/fbrocket/download.php?d=bin&v=0.1a )
- Make sure you have created an application inhttp://www.facebook.com/developers/#!/developers/createapp.php
- Note down application name and API key, do not reveal API key to anybody.
[sourcecode language="java"]
package org.androidpeople.facebook;
package org.androidpeople.facebook;
import net.xeomax.FBRocket.FBRocket;
import net.xeomax.FBRocket.Facebook;
import net.xeomax.FBRocket.LoginListener;
import net.xeomax.FBRocket.ServerErrorException;
import android.app.Activity;
import android.os.Bundle;
import net.xeomax.FBRocket.Facebook;
import net.xeomax.FBRocket.LoginListener;
import net.xeomax.FBRocket.ServerErrorException;
import android.app.Activity;
import android.os.Bundle;
public class FacebookRocketExample extends Activity implements LoginListener {
private FBRocket fbRocket;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
shareFacebook();
}
}
public void shareFacebook() {
fbRocket = new FBRocket(this, "Your App Name",
"Your API Key");
fbRocket = new FBRocket(this, "Your App Name",
"Your API Key");
if (fbRocket.existsSavedFacebook()) {
fbRocket.loadFacebook();
} else {
fbRocket.login(R.layout.main);
}
}
fbRocket.loadFacebook();
} else {
fbRocket.login(R.layout.main);
}
}
@Override
public void onLoginFail() {
fbRocket.displayToast("Login failed!");
fbRocket.login(R.layout.main);
}
public void onLoginFail() {
fbRocket.displayToast("Login failed!");
fbRocket.login(R.layout.main);
}
@Override
public void onLoginSuccess(Facebook facebook) {
// TODO Auto-generated method stub
fbRocket.displayToast("Login success!");
public void onLoginSuccess(Facebook facebook) {
// TODO Auto-generated method stub
fbRocket.displayToast("Login success!");
try {
facebook.setStatus("This is your status");
fbRocket.displayDialog("Status Posted Successfully!! "
+ facebook.getStatus());
} catch (ServerErrorException e) {
if (e.notLoggedIn()) {
fbRocket.login(R.layout.main);
} else {
System.out.println(e);
}
}
}
facebook.setStatus("This is your status");
fbRocket.displayDialog("Status Posted Successfully!! "
+ facebook.getStatus());
} catch (ServerErrorException e) {
if (e.notLoggedIn()) {
fbRocket.login(R.layout.main);
} else {
System.out.println(e);
}
}
}
}
[/sourcecode]
[/sourcecode]
Download : This Example Click Here
No comments:
Post a Comment