簡體   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