0

I am sharing link and Image from URL using this code

private UiLifecycleHelper uiHelper
    String fbPhotoAddress = null;       

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, null);
        uiHelper.onCreate(savedInstanceState);


    }

void btn_clicked(View view)
{
FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
            .setApplicationName("fiver").
            setLink("https://play.google.com/store/")
            .setPicture("http://www.sweetkidsapps.com/wp-content/uploads/2013/02/cool-coloring-great-kids-app.jpg")
            .build();

            uiHelper.trackPendingDialogCall(shareDialog.present());

}

and it is working fine but the issue is that I want to upload image on Facebook and get its URL to send in setPicture, How can I do this?

ps Things that I checked on Google are mostly outdated.

Bilal Haider
  • 173
  • 1
  • 3
  • 14

1 Answers1

0

I'm not sure that you are thinking it in the right way.

Facebook Share Dialog allow you to post a picture from URL with other stuff like a link, a description, a caption and a name.

The Post with all these data will be posted without any aditional permission.

If yout want to upload and post a picture from local you need to do something like this:

   Request request = Request.newUploadPhotoRequest(
            session,
            ((BitmapDrawable) getResources().getDrawable(
                    R.drawable.picture)).getBitmap(), callback);
    RequestAsyncTask task = new RequestAsyncTask(request);
    task.execute();

The problem with this way is that you will need to add "publish_actions" permissions in your facebook app, and to do a login to facebook in order to obtain an active "session".

More info here --> https://developers.facebook.com/docs/facebook-login/permissions/v2.1

and here --> https://developers.facebook.com/docs/android/share/

Can I suggest to upload your image in some place, like a dropbox public folder, and get the url from there? This is infinitelly easier

jDur
  • 1,481
  • 9
  • 10
  • Thanks! Let me try this first – Bilal Haider Oct 17 '14 at 12:00
  • I get this error '{Response: responseCode: 400, graphObject: null, error: {HttpStatus: 400, errorCode: 2500, errorType: OAuthException, errorMessage: An active access token must be used to query information about the current user.}, isFromCache:false}' – Bilal Haider Oct 19 '14 at 11:13