Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I simply share content on Facebook wall using its Android SDK?

I cannot find many examples of the FB + Android SDK and the samples are not simple enough(some of them are deprecated). My simple goal is to share some content on FB using my Android app. When I developed the iOS app it was simply

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate facebookLogin];


NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"pikSpeak", @"name",
                               shareURL, @"link",
                               @"pikSpeak for iPhone !", @"caption",
                               @"Record audio at the moment of the image taken using pikSpeak and feel the moment come alive", @"description",
                               @"shared an audible pic using pikSpeak cam", @"message",
                               imageURL,@"picture",
                               nil];

[[appDelegate facebook] requestWithGraphPath:@"feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

This code handled the sessions and saving the session details over app restarts.

1) How to simply share some thing in Android.

2) I saw Facebook(String app_id) is deprecated. If so, then what is its replacement?

P.S. : Using Facebook 3.0 SDK

like image 954
rahulg Avatar asked Mar 30 '13 05:03

rahulg


People also ask

How do you share an app on Facebook?

People can share photos from your app to Facebook with the Share Dialog. In order to share, they must have the native Facebook for Android app installed, version 7.0 or higher. Build your share content for photos into the SharePhotoContent model. For a list of all attributes, see SharePhotoContent reference.


1 Answers

Taken from Share on User's Wall using Facebook SDK:

private void share() {
    Bundle bundle = new Bundle();
    bundle.putString("caption", "Harlem Shake Launcher for Android");
    bundle.putString("description", "Your android can do the Harlem Shake. Download it from google play");
    bundle.putString("link", "https://play.google.com/store/apps/details?id=mobi.shush.harlemlauncher");
    bundle.putString("name", "Harlem Shake Launcher");
    bundle.putString("picture", "http://shush.mobi/bla.png");
    new WebDialog.FeedDialogBuilder(mContext, mySession, bundle).build().show();
}

If you need to login (add this in you activity wherever you need to login/share):

Session.openActiveSession(this, true, new Session.StatusCallback() {

    @Override
    public void call(Session session, SessionState state, Exception exception) {
        if(session.isOpened()) {
            share();
        }
    }
});

You will need to add to your activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode) {
    default:
        if(Session.getActiveSession() != null) //I need to check if this null just to sleep peacefully at night
            Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
        break;
    }
}
like image 190
Sherif elKhatib Avatar answered Sep 23 '22 04:09

Sherif elKhatib