Facebook Unity API - post screenshot with link and description?

蹲街弑〆低调 提交于 2019-12-06 12:02:43
    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 refer here for more details of the available fields

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

After you upload the screenshot using your code above, check the FBResult from your callback method and parse the result with key "id" so you got your uploaded photo id.

Your photo link will be "https://www.facebook.com/photo.php?fbid=INSERT_YOUR_ID" as the INSERT_YOUR_ID is the id from the result before. Use that link on FB.Feed.

Khalid Mahmood

Follow these steps:

  1. First login using FB.LogInWithPublishPermissions by adding the "publish_actions" permission in parameters.
  2. Use Facebook Graph API to upload the image.

For more details link is here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!