2

我正在尝试让我的应用程序(iOS、Android)允许用户将屏幕截图发布到 Facebook,并附上链接和描述。我可以使用 FB.API() 将屏幕截图从我的应用程序上传到 Facebook 为我的应用程序自动生成的用户相册,方法是:

    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); 

而且我可以使用 FB.Feed() 从互联网上发布一张图片,其中包含一个链接和对用户提要的描述。有没有办法通过链接和描述将屏幕截图发布到用户的提要?

4

3 回答 3

2
    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);

您可以参考此处了解可用字段的更多详细信息

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

于 2015-02-07T15:59:45.410 回答
1

使用上面的代码上传屏幕截图后,检查回调方法中的 FBResult 并使用键“id”解析结果,以便获得上传的照片 ID。

您的照片链接将是“ https://www.facebook.com/photo.php?fbid=INSERT_YOUR_ID ”,因为 INSERT_YOUR_ID 是之前结果中的 id。在 FB.Feed 上使用该链接。

于 2014-02-27T09:46:47.743 回答
0

按着这些次序:

  1. 首次登录使用FB.LogInWithPublishPermissions通过在参数中添加"publish_actions"权限。
  2. 使用Facebook Graph API上传图片。

更多详情链接在这里

于 2017-08-03T13:39:05.607 回答