Created
February 2, 2011 15:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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