使用Facebook SDK来上传截图在Unity [英] Using Facebook SDK to Upload Screenshot in Unity
问题描述
我想使用Facebook的SDK来使用截图上传至Facebook FB.Feed()
而不是 FB.API()
,以便用户可以编写一个消息给他们的岗位。我能得到这个团结编辑器中工作,但是当我尝试在我的Android,我得到:
这个对话框已通过了一项糟糕的参数。
API错误code:100结果
API错误说明:无效的参数结果
错误信息:图片网址的格式不正确
块引用>这里是code我写的:
VAR WIDTH = Screen.width;
VAR HEIGHT = Screen.height;
变种特克斯=新的Texture2D(宽度,高度,TextureFormat.RGB24,假);
//读取屏幕内容到纹理
tex.ReadPixels(新的Rect(0,0,宽度,高度),0,0);
tex.Apply();
字节[] =截图tex.En codeToPNG();
File.WriteAllBytes(Application.persistentDataPath +/Screenshot.png截图);//Application.CaptureScreenshot(Application.persistentDataPath +/Screenshot.png);
的debug.log(Application.persistentDataPath +/Screenshot.png);
的debug.log(文件是否存在?+ File.Exists(Application.persistentDataPath +/Screenshot.png));
的debug.log(文件://+ Application.persistentDataPath +/Screenshot.png);
FB.Feed(
图片:文件://+ Application.persistentDataPath +/Screenshot.png
);
解决方案您无法使用
FB.Feed()
,图片
parametr必须在网页的URL。要上传您可以使用图像
FB.API(ME /照片)
法私人无效TakeScreenshot()
{
VAR WIDTH = Screen.width;
VAR HEIGHT = Screen.height;
变种特克斯=新的Texture2D(宽度,高度,TextureFormat.RGB24,假);
//读取屏幕内容到纹理
tex.ReadPixels(新的Rect(0,0,宽度,高度),0,0);
tex.Apply();
字节[] =截图tex.En codeToPNG(); WWWForm wwwForm =新WWWForm();
wwwForm.AddBinaryData(形象,截图,screenshot.png); FB.API(ME /照片,HttpMethod.POST回调,wwwForm);
}I'm am trying to use Facebook SDK to Upload Screenshots to Facebook using
FB.Feed()
instead ofFB.API()
so that users can write a message to their post. I was able to get this to work on Unity Editor but when I try it on my Android, I get:"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"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.To upload image you may use
FB.API("me/photos")
methodprivate 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); }
这篇关于使用Facebook SDK来上传截图在Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!