gpt4 book ai didi

android - 在Unity中使用Facebook SDK上传截图

转载 作者:太空狗 更新时间:2023-10-29 15:05:06 25 4
gpt4 key购买 nike

我正在尝试使用 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"
);

最佳答案

不能使用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);
}

关于android - 在Unity中使用Facebook SDK上传截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22739066/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com