使用Facebook SDK来上传截图在Unity [英] Using Facebook SDK to Upload Screenshot in Unity

查看:3061
本文介绍了使用Facebook SDK来上传截图在Unity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Facebook的SDK来使用截图上传至Facebook FB.Feed()而不是 FB.API(),以便用户可以编写一个消息给他们的岗位。我能得到这个团结编辑器中工作,但是当我尝试在我的Andr​​oid,我得到:


  

这个对话框已通过了一项糟糕的参数。


  
  

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 of FB.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") method

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

这篇关于使用Facebook SDK来上传截图在Unity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆