1

I want to post a predefind message with link on facebook wall without user intervention .I mean user just log into facebook and my predefind message should be post with link on user's facebook wall.

Below is my code.

public class PostOnFacebookWall {
    public static void postOnWall(Facebook facebook , final Context context, final String placeName) {
        Bundle params = new Bundle();
        params.putString("message", placeName);
        facebook.dialog(context, "feed", params ,new DialogListener() {

            public void onFacebookError(FacebookError e) {
            }

            public void onError(DialogError e) {
            }

            public void onComplete(Bundle values) {
                Toast.makeText(context, placeName+" for today's hangout has been posted on your facebook wall. ", Toast.LENGTH_LONG).show();
            }

            public void onCancel() {
            }
        });
    }
}

I've looked so many links about my question like below

http://stackoverflow.com/questions/11316683/adding-content-to-facebook-feed-dialog-with-new-facebook-sdk-for-android

which passed all the parameter like "link","description","image" and much more. Someone is saying that u have to pass all the parameters.I just want to predefind messages and link over that.

My message is should be "Let's hangout at " and here placeName should be a link. And this complete msg i want to pass from my code .I don't want that my code opens dialog where user enters it's message.

ved
  • 909
  • 2
  • 17
  • 43

1 Answers1

1

If you need to post a predefined message to a User's Facebook Wall, you shouldn't be using the facebook.dialog method.

For more on why that shouldn't be used, read my answer posted here: https://stackoverflow.com/a/13507030/450534

That being said, to get the result you want, try this piece of code:

Bundle postStatusMessage = new Bundle();

// ADD THE STATUS MESSAGE TO THE BUNDLE
postStatusMessage.putString("message", "Let's hangout at " + placeName);
postStatusMessage.putString("link", "www.the_example_web_address.com");

Utility.mAsyncRunner.request("me/feed", postStatusMessage, "POST", new StatusUpdateListener(), null);

And this is where you can check the response from the Facebook API by parsing the String response:

private class StatusUpdateListener extends BaseRequestListener  {

    @Override
    public void onComplete(String response, Object state) {

}

A point to note here is, you cannot pass a message with a link in it. To elaborate (as the earlier statement might sound confusing), You cannot pass a link in the message tag with a link that will be parsed by Facebook and show up in a post like links on FB do.

To see the difference clearly, post the status update using the code above and see how it looks on Facebook. Then, after having done that, remove this postStatusMessage.putString("link", "www.the_example_web_address.com"); from the code above and include the link in the message tag, post it and see how it looks on Facebook.

Community
  • 1
  • 1
Siddharth Lele
  • 27,623
  • 15
  • 98
  • 151
  • how did you pass 5 parameters in request() function. It just takes 3 parameters. – ved Dec 01 '12 at 12:52
  • @ved: Which parameters do you want to pass? – Siddharth Lele Dec 01 '12 at 12:54
  • I've used response = facebook.request("me/feed", params, "POST" ); – ved Dec 01 '12 at 13:14
  • siddharth , 1 more thing... I am receiving error in response {"error":{"message":"An active token must be used to query information about the current user.","type":"OAuthException","code":2500}} I think , for posting wall , i've to signin in account. – ved Dec 01 '12 at 13:40