繁体   English   中英

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

[英]Posting screenshot through Facebook SDK for Unity

将屏幕截图发布到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并粘贴命令“ me?fields = photos”时,我什么也没得到。 这意味着功能什么也没做。 我忘了说我授予了user_photos的权限。 这真令人沮丧。 我在看似微不足道的问题上损失了三天,但看不到解决方案。 我将不胜感激任何建议。

现在,没有简单的方法可以通过FB.API处理此问题,因为它接受了Dictionary<string, string>

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM