我正在尝试使用Facebook SDK使用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"
);
答案 0 :(得分:0)
您无法使用FB.Feed()
将图片上传到Facebook,picture
参数必须是网址中的网址。
要上传图片,您可以使用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);
}