Android 使用Facebook SDK在Unity中上传屏幕截图

Android 使用Facebook SDK在Unity中上传屏幕截图,android,facebook,url,unity3d,Android,Facebook,Url,Unity3d,我正在尝试使用FacebookSDK,使用FB.Feed()而不是FB.API()将屏幕截图上传到Facebook,这样用户就可以在自己的帖子上写消息了。我能够在Unity Editor上使用它,但当我在Android上尝试时,我得到: “此对话框传递了一个错误的参数 API错误代码:100 API错误描述:无效参数 错误消息:图片URL格式不正确“ 这是我写的代码: var width = Screen.width; var height = Screen.height; var tex =

我正在尝试使用FacebookSDK,使用
FB.Feed()
而不是
FB.API()
将屏幕截图上传到Facebook,这样用户就可以在自己的帖子上写消息了。我能够在Unity Editor上使用它,但当我在Android上尝试时,我得到:

“此对话框传递了一个错误的参数

API错误代码:100
API错误描述:无效参数
错误消息:图片URL格式不正确“

这是我写的代码:

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

您不能使用
FB.Feed()
将图像上载到facebook,
picture
参数必须是web中的url

要上传图像,您可以使用
FB.API(“我/照片”)
方法

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