簡體   English   中英

無法在Unity Facebook SDK中使用www獲取Facebook個人資料圖片

[英]Cannot Get Facebook Profile Picture Using www in Unity Facebook SDK

我正在嘗試使用適用於Unity 7.3.0的Facebook SDK從graph.facebook.com獲取個人資料圖片。 我的Unity版本是5.3。

這是我的職責

public static IEnumerator GetFBProfilePicture (){
    WWW url = new WWW (System.Uri.EscapeUriString("https://graph.facebook.com/" + someUserID + "/picture?type=large"));
    yield return url;
    Debug.Log("Completed.");
    Texture2D texture = new Texture2D (180, 180, TextureFormat.DXT1, false);
    url.LoadImageIntoTexture (texture);
    // ...

}

我把這個功能叫做

    StartCoroutine (GetFBProfilePicture ());

它在Unity Player和Android設備中都可以正常工作。 但是在iOS設備上,“已完成”。 線不顯示。 而且沒有錯誤日志。 它只是在url行中一直等待。

我在帶有無線連接和移動數據的iOS 7和9上進行了嘗試。 問題仍然出現。

我遇到了同樣的問題,終於找到了解決方案(盡管不是理想的解決方案)。 使用參數redirect = false發出請求似乎可以解決問題,但隨后它僅返回圖像的url,而不返回圖像本身。 因此,您將不得不再次請求該圖像。 以下代碼概述了解決方案:

//passed in URL looks like https://graph.facebook.com/some_id/picture?type=large
IEnumerator GetDownloadURL(string url, float pixelsPerUnit = 100.0f ) {
    url = url + "&redirect=false";
    WWW www = new WWW(url);
    yield return www;
    Dictionary<string,object> dict = fastJSON.JSON.Parse(www.text) as Dictionary<string,object>;
    Dictionary<string,object> dataDict = dict["data"] as Dictionary<string,object>;
    DownloadImage(dataDict["url"])
}

IEnumerator DownloadImage(string url ) {
    WWW www = new WWW(url);
    yield return www;
    Texture2D texture = newDownload.www.texture;
    ///...
}

推薦解決方案的已知問題: https : //developers.facebook.com/x/bugs/364606280347510/

我用這個就行了,嘗試一下

IEnumerator getPicture(string url, SpriteRenderer spritex) {
    WWW www = new WWW (url);
    yield return www;
    Sprite sprite = new Sprite ();
    sprite = Sprite.Create (www.texture, new Rect (0, 0, 50, 50), new Vector2 (0.5f, 0.5f), 100.0f);
    spritex.sprite = sprite;
    www.LoadImageIntoTexture (spritex.sprite.texture);
}

事情是創建一個新的精靈,不確定為什么,但是它像那樣工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM