Share an Image on Faceook

Hey guys, I want to share a screen shot to Facebook with other text content (if possible) or without any content. I found 2 way and I tried both of them none seems to be working perfectly.

I am using Facebook SDK for unity v7.2.2 and unity 5.4.2f2.

The 1st way I deed is using FB.Sharelink. Here is a step by step information about it.

  1. Take the screenshot

  2. Store to application.persistendatapath

  3. Upload to other own hosted server

  4. File successfully uploaded on server.

  5. Now put the game for manual wait for 10 second for image uploading.

  6. Once image uploaded on server Facebook sharing dialog appears on device. Current stored image is getting displayed on server.

  7. Post it to Facebook. all post content were fine on dialog on device.

Result at end:.
When I saw my post on Facebook i saw other no image and other text content was there.

No when I try to post it on second time what i found on Facebook share dialog is "instead of displaying current saved image on device, Facebook dialog shows previous shared image and when I post it to Facebook it shows other images. it didn’t showed previous image also. in post it showing the image that was uploaded 2-3 days ago.

The 2nd way is using FB.API call. Here is the step by step information for executing it

  1. Here is code for that

    byte imgData = File.ReadAllBytes (Application.persistentDataPath + “/” + fUserName.Value +
    Texture2D imgtex = new Texture2D (333,333);
    imgtex.LoadImage (imgData);
    WWWForm wwwForm = new WWWForm ();
    FB.API (“me/photos”, Facebook.Unity.HttpMethod.POST, ShareCallBack, wwwForm);

  2. When I executed above code I got response back saying “403:Forbidden”. It simply means I have authority to use respected website page.

  3. I am using FB.LoginWithReadPermission with following permission :. public_profile, email, user_friends. Do I have to use FB.LoginwithWritePermission with particular permission ?

Please help me on this.
Thanks in advance.

You need ask “publish_actions” permission too. Check out the link below.

For anyone who is looking for share screenshot to FB directly, please check the answer there.

You can generalize that with the notion of sharing “intent”. There is a Github project that covers that here and I’ve put together a detailed answer to cover also IOS, all here.