An SO User
An SO User

Reputation: 24998

Posting something to status on Facebook

I am using this tutorial to learn how to connect to Facebook via Android app. I am particularly interested in the section where he shows how to post something on the wall / status of the user.

The tutorial is fairly straightforward however my requirement is that I need to let the app append things along with what the user posts.

How can that be achieved ?

Upvotes: 0

Views: 95

Answers (2)

Muhammad Aamir Ali
Muhammad Aamir Ali

Reputation: 21097

You have to open the session as session.openForPublish(); and you required permission "publish_action"

Upvotes: 1

Sushil
Sushil

Reputation: 8488

You can do something like this:

private void publishToFacebook(String message)
      {
            long songId = MusicUtils.getCurrentAudioId();
                long albumId = MusicUtils.getCurrentAlbumId();
            String albumartUrl = MusicUtils.getArtworkUrlFromExtrasCache(getApplicationContext(),albumId);
            Bitmap bm = MusicUtils.getArtworkFromExtrasCache(getApplicationContext(),albumId,false,false);
            if(bm == null)
            bm = MusicUtils.getDefaultArtwork(getApplicationContext());

                shareFacebookConnector = new ShareConnector(MediaPlaybackActivity.this, getApplicationContext());
            shareFacebookConnector.setCurrentAlbum(MusicUtils.getCurrentAlbumName());
            shareFacebookConnector.setCurrentArtist(MusicUtils.getCurrentArtistName());
            shareFacebookConnector.setCurrentTrack(MusicUtils.getCurrentTrackName());
        shareFacebookConnector.setCurrentCoverArt(bm);
        if(albumartUrl != null)
        {
        shareFacebookConnector.setCurrentCoverUrl(albumartUrl);
        }

        LayoutInflater inflater = this.getLayoutInflater();
        final View dialoglayout = inflater.inflate(R.layout.facebook_share, (ViewGroup) findViewById(R.id.facebook_share_root));
        final ImageView image = (ImageView) dialoglayout.findViewById(R.id.facebook_cover_view);
        input = (EditText) dialoglayout.findViewById(R.id.facebook_share_content);
        ContextThemeWrapper ctw = new ContextThemeWrapper(this, R.style.AlertDialogCustom);
        AlertDialog.Builder alert = new AlertDialog.Builder(ctw);   
        if(message != null)
        {
                shareFacebookConnector.publishToFacebook(alert, input, message);    
        }
        else
        {
        shareFacebookConnector.publishToFacebook(alert, input, null);  
        }
        alert.setView(dialoglayout);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {  
            bAlertInProgress = false; 
            String messageToPost = input.getText().toString();
            shareFacebookConnector.postMessageToWall(messageToPost, false);         
        } 
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            bAlertInProgress = false;
            Toast.makeText(MediaPlaybackActivity.this, "Wall post cancelled !", Toast.LENGTH_SHORT).show();
            //finish();    

        }
    });
    bAlertInProgress = true;
    mShareKey = "********";
    alertDialog = alert.create();
    alertDialog.show();
}

Upvotes: 1

Related Questions