I'm using Facebook SDK and I want to post message on my wall. It's near two days that I plow the Internet but i was not successful to find my problem. Let me say what I did.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Try to create activity...");
// Close activity if app id is not specified.
if (FACEBOOK_APPID == null || FACEBOOK_APPID == "") {
Log.e(TAG, "Facebook Applicaton ID must be specified before running this screen.");
closeActivity();
}
// Getting extra info which is passed by caller activity.
// If we are here by mistake(Caller didn't send required parameter) close activity.
Bundle extras = getIntent().getExtras();
if(extras == null) {
Log.i(TAG, "No data passed to this activity. Activity closed.");
closeActivity();
}
// Get Message
message = extras.getString("FB_WALLPOST");
// Log.i(TAG, "message>>> " + message);
mFacebook = new Facebook(FACEBOOK_APPID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
SessionStore.restore(mFacebook, this);
SessionEvents.addAuthListener(new SampleAuthListener());
SessionEvents.addLogoutListener(new SampleLogoutListener());
// mFacebook.dialog(FacebookActivity.this, "feed", params, new SampleDialogListener());
Thread thread = new BasicThread();
thread.start();
}
Based on my research I found that Facebook.dialog
cannot be used. That's why Its commented out.
Also I found that we need to use Facebook.request
instead of that. I found Note that this method blocks waiting for a network response, so do not call it in a UI thread.
in its implementation in SDK. Therefore, I created another thread to handle posting process.
When thread starts following method will be invoked.
public class BasicThread extends Thread {
public void run() {
try{
Bundle parameters = new Bundle();
parameters.putString("message", "Text is lame. Listen up:");
parameters.putString("name", "Name");
parameters.putString("link", "http://www.google.com");
parameters.putString("caption", "Caption");
parameters.putString("description", "Description");
String response = mFacebook.request("me/feed",parameters,"POST");
Log.v("response", response);
}
catch(Exception e){}
}
}
Those people who suggested this code had been told that the method works fine for them. However, I have no idea why it doesn't work for me.
response in logcat:
09-16 17:06:21.860: D/Facebook-Util(26652): POST URL: https://graph.facebook.com/me/feed
09-16 17:06:23.350: V/response(26652): {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
Any suggestions would be appreciated. Thanks
No access token is being sent, though, is it? Try something like:
String token = getAccessToken();
if (token){
parameters.putString("access_token", token);
String response = mFacebook.request("me/feed",parameters,"POST");
} else {
// Log the user in
}