使用Facebook SDK在Unity中上传截图

3
我正尝试使用Facebook SDK通过FB.Feed()而不是FB.API()上传屏幕截图到Facebook,以使用户能够在其帖子中写下消息。我已经成功地在Unity Editor上实现了这一点,但是当我在Android上尝试时,我收到以下错误信息:

"This dialog has been passed a bad parameter.

API Error Code: 100
API Error Description: Invalid parameter
Error Message: picture URL is not properly formatted"

这是我编写的代码:
var width = Screen.width;
var height = Screen.height;
var 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();
File.WriteAllBytes(Application.persistentDataPath + "/Screenshot.png", screenshot);

//Application.CaptureScreenshot(Application.persistentDataPath + "/Screenshot.png");
Debug.Log(Application.persistentDataPath + "/Screenshot.png");
Debug.Log("Does File Exist? " + File.Exists(Application.persistentDataPath + "/Screenshot.png"));
Debug.Log("File://" + Application.persistentDataPath + "/Screenshot.png");
FB.Feed(
    picture: "File://" + Application.persistentDataPath + "/Screenshot.png"
);
1个回答

0

使用FB.Feed()无法将图片上传到Facebook,picture参数必须是Web中的URL。

要上传图片,您可以使用FB.API("me/photos")方法。

private void TakeScreenshot()
{
    var width = Screen.width;
    var height = Screen.height;
    var 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();

    WWWForm wwwForm = new WWWForm();
    wwwForm.AddBinaryData("image", screenshot, "screenshot.png");

    FB.API("me/photos", HttpMethod.POST, CallBack, wwwForm);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接