通过Facebook SDK for Unity发布屏幕截图

时间:2013-09-17 07:57:54

标签: facebook unity3d screenshot

我将截图发布到FB时遇到问题。连接不是问题,因为我收集,反序列化并显示我的fb数据。将评分和消息发布给朋友工作正常,但我无法通过手机发布一个镜头。我正在使用Eclipse进行调试,但我没有收到任何错误。我的代码看起来像这样: `

IEnumerator TakeScreenShot()
{    
        //coroutine because I want to wait until end of the frame for shot
   yield return new WaitForEndOfFrame();
    //create new texture that will be my screenshot
      Texture2D tex = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24, false); 
        // read pixels from screen
       tex.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0); 
        //and apply them to texture
      tex.Apply(); 
        // now we have screenshot
        // now we need to encode texture to array of bytes
       byte[] buffer = tex.EncodeToPNG();
    //so we can save it to storage 
    // System.IO.File.WriteAllBytes(Application.dataPath + "/screenshots/screen/screen" + ".png", buffer);  
        //or to convert it to string for posting to facebook
       string s = Convert.ToBase64String(buffer);
        //????? maybe my string format is not correct
       var query = new Dictionary<string, string>();
       query["photos"] = s;
       FB.API("me?fields=photos",Facebook.HttpMethod.POST, delegate (string r) { ;     }, query);
        }    

` 当我去GraphExplorer并粘贴命令“我?fields = photos”时我什么都没得到。这意味着功能什么也没做。我忘了说我已经授予了user_photos的许可。这令人沮丧。我已经失去了三天看起来微不足道的问题,但看不到任何解决方案。我将不胜感激任何建议。

1 个答案:

答案 0 :(得分:1)

现在通过FB.API处理此问题并不容易,因为它需要Dictionary<string, string>

然而FB.API()实际上只是Unity WWW类的包装器。您可以在graph.facebook.com调用图表端点,并将byte[] buffer = tex.EncodeToPNG()作为WWWForm()中的参数传递。

更新:FB.API()已在4.3.3版中更新,以支持WWWForm。您现在可以通过该方法上传照片。