Facebook Unity API - post screenshot with link and description?

I am trying to get my application (iOS, Android) so that users can post a screenshot to facebook with a link and description. I can use FB.API () to upload screenshots from my application to the user album that Facebook was created for my application through:

int width = Screen.width; int height = Screen.height; Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false); // Read screen contents into the texture tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply(); byte[] screenshot = tex.EncodeToPNG(); var wwwForm = new WWWForm(); string picName = "Idioman_" + Time.time + ".png"; wwwForm.AddBinaryData("image", screenshot, picName); Debug.Log("trying to post screenshot"); FB.API("me/photos", Facebook.HttpMethod.POST, PostPicCallback, wwwForm); 

And I can use FB.Feed () to publish an image from the Internet with a link and description in the user's feed. Is there a way to post a screenshot in the user's feed with a link and description?

+2
source share
3 answers
  var snap = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); snap.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); snap.Apply(); var screenshot = snap.EncodeToPNG(); int i = UnityEngine.Random.Range (0, 2); var wwwForm = new WWWForm(); wwwForm.AddBinaryData("image", screenshot, "picture.png"); wwwForm.AddField ("name", "this will be the caption for the image"); FB.API("me/photos", HttpMethod.POST, CallbackUploadImage, wwwForm); 

You can contact here for more information on the available fields.

https://developers.facebook.com/docs/graph-api/reference/v2.2/photo

+2
source

After you upload the screenshot using your code above, check FBResult for your callback method and analyze the result using the "id" key so that you get your loaded photo id.

Your link to the photo will be " https://www.facebook.com/photo.php?fbid=INSERT_YOUR_ID " because INSERT_YOUR_ID is the result identifier. Use this link to FB.Feed.

+1
source

Follow these steps:

  • First log in using FB.LogInWithPublishPermissions by adding the "publish_actions" permission to the parameters.
  • Use the Facebook Graph API to download the image.

For more information link here .

0
source

Source: https://habr.com/ru/post/969970/


All Articles