【问题标题】:Using Facebook SDK to Upload Screenshot in Unity在 Unity 中使用 Facebook SDK 上传截图
【发布时间】:2014-05-09 11:07:24
【问题描述】:

我正在尝试使用 Facebook SDK 使用 FB.Feed() 而不是 FB.API() 将屏幕截图上传到 Facebook,以便用户可以在他们的帖子中写入消息。我能够让它在 Unity 编辑器上工作,但是当我在我的 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"
);

【问题讨论】:

    标签: android facebook url unity3d


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      相关资源
      最近更新 更多