Skip to content

Instantly share code, notes, and snippets.

@mokkun
Created February 2, 2011 15:17
Show Gist options
  • Save mokkun/807825 to your computer and use it in GitHub Desktop.
Save mokkun/807825 to your computer and use it in GitHub Desktop.
Simple example of how to post a message using the Facebook SDK. I'm assuming that the user is already logged in.
Context context = this.getApplicationContext();
Facebook facebook = new Facebook(YOUR_FACEBOOK_ID);
AsyncFacebookRunner facebookAsync = new AsyncFacebookRunner(facebook);
Handler facebookHandler = new Handler();
SessionStore.restore(facebook, context);
Bundle params = new Bundle();
params.putString("message", "This is my message.");
facebookAsync.request("me/feed", params, "POST", new RequestListener() {
public void onMalformedURLException(MalformedURLException e) {}
public void onIOException(IOException e) {}
public void onFileNotFoundException(FileNotFoundException e) {}
public void onFacebookError(FacebookError e) {
facebookHandler.post(new Runnable() {
public void run() {
Toast.makeText(context, "Error when posting the message.", Toast.LENGTH_LONG).show();
}
});
}
public void onComplete(String response) {
facebookHandler.post(new Runnable() {
public void run() {
Toast.makeText(context, "Message published!", Toast.LENGTH_LONG).show();
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment