8

In my android app, I want users to "share" my app in their wall, so I want them to post a predefined content status on their wall.

How can I customize the wall status? (I want to add my app icon and some flare text).

Kara
  • 6,115
  • 16
  • 50
  • 57
oriharel
  • 10,418
  • 14
  • 48
  • 57

4 Answers4

5

Download the Facebook SDK and import it in your project. Then use the following code to Authorize:

    public void sendtoFacebook(){
        facebookClient = new Facebook("<Your_APP_ID");
        facebookClient.authorize(<Current_class>.this, new AuthorizeListener());
    }

Now you have to add the following methodes:

class AuthorizeListener implements DialogListener {
    public void onComplete(Bundle values) {
        Bundle parameters = new Bundle();
            parameters.putString("message", "<Message_you_want_to_send>");// the message to post to the wall
            facebookClient.dialog(<Current_class>.this, "stream.publish", parameters, this);// "stream.publish" is an API call
    }
    @Override
    public void onFacebookError(FacebookError e) {
    }
    @Override
    public void onError(DialogError e) {
    }
    @Override
    public void onCancel() {
    }
}

Your Application name and Icon will automatically be added :)

Galip
  • 5,435
  • 10
  • 37
  • 47
  • Thanks, but this is not exactly what I want. this one puts text in the text box. I want to give the user opportunity to add text on top of the predefined content. When you share a video from YouTube, there is a dialog the pops up, an empty textbox for you to add status, and below a YouTube content (in this example, an embedded video and text). this is the experience I want my users to have. – oriharel Dec 15 '10 at 14:27
  • The code i posted is just a simple post to a wall. If you look through the SDK at https://github.com/facebook/facebook-android-sdk you'll see there are plenty more options, including the ones you want. – Galip Dec 15 '10 at 14:30
  • Actually the documentation in this page is pretty minimal (i.e. there is no list of optional parameters to add to the bundle). I guess Facebook API (the standard, not android) is assumed. – oriharel Dec 15 '10 at 14:46
  • 5
    `message` field ignored from July 12, 2011. See: http://developers.facebook.com/docs/reference/dialogs/feed/ – jamapag Sep 02 '11 at 08:48
  • @jamapag does it replaced by another field? is there a way in the current API to set content to the post? – shem Jul 03 '12 at 17:26
  • @shem from facebook sdk dialog it's not possible, but you can create custom dialog, and send data by requesting to "me/feed". – jamapag Jul 04 '12 at 11:45
3

After learning the Facebook API, I came across this page

so now I know all the options for the bundle parameters. Thanks everyone for your help!

oriharel
  • 10,418
  • 14
  • 48
  • 57
2

This is how I am making a bundle to set content via a facebook dialog using the Facebook SDK

Bundle parameters = new Bundle();
        parameters.putString("app_id", "xxxxxxx");
        parameters.putString("link", "https://play.google.com/store/apps/details?id=myappistasty");
        parameters.putString("name", "This is the name of the link set in app.");
        parameters.putString("caption", "This is Text that is specified in bt the aoo");
        parameters.putString("picture", "www.urltoimage.com);
facebook.dialog(MainActivity.this, "feed", parameters, new DialogListener() {
etc...

http://developers.facebook.com/docs/reference/dialogs/feed/ this is the link that explained all to me, although none of it is in java the table gives you a good idea.

Aiden Fry
  • 1,672
  • 3
  • 21
  • 45
2

You can also do that without the SDK, just via Share URL:

public void shareOnFacebook(View v) {

    Uri uri = Uri.parse("http://m.facebook.com/sharer.php?u=http://yourdomain/page.html&t=YourMessage");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
}

You just need to put a content page / html somewhere on your server, under the url your provided to the sharer.

If you want that a certain image appears in the shared message, put this in the meta tag of your html page on the server that you're sharing:

<link rel="image_src" type="image/jpeg" href="http://yourdomain.com/promo/image.png" /> 

See a sample of such promo page with linked image: http://www.modelme.co.uk/promo/amandaharrington

Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192