[英]Using Facebook SDK to Upload Screenshot in Unity
I'm am trying to use Facebook SDK to Upload Screenshots to Facebook using FB.Feed()
instead of FB.API()
so that users can write a message to their post. 我正在尝试使用Facebook SDK使用FB.Feed()
而不是FB.API()
将屏幕截图上传到Facebook,以便用户可以将消息写入其帖子。 I was able to get this to work on Unity Editor but when I try it on my Android, I get: 我能够在Unity Editor上使用它,但是当我在Android上试用它时,我得到:
"This dialog has been passed a bad parameter. “此对话框已传递错误参数。
API Error Code: 100 API错误代码:100
API Error Description: Invalid parameter API错误说明:参数无效
Error Message: picture URL is not properly formatted" 错误消息:图片URL格式不正确“
And here is the code I wrote: 这是我写的代码:
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"
);
You can't upload image to facebook using FB.Feed()
, picture
parametr must be url in web. 您无法使用FB.Feed()
将图像上传到Facebook, picture
参数必须是网页中的网址。
To upload image you may use FB.API("me/photos")
method 要上传图像,您可以使用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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.