简体   繁体   English

无法在Unity Facebook SDK中使用www获取Facebook个人资料图片

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

I'm trying to get profile picture from graph.facebook.com using Facebook SDK for Unity 7.3.0. 我正在尝试使用适用于Unity 7.3.0的Facebook SDK从graph.facebook.com获取个人资料图片。 My Unity version is 5.3. 我的Unity版本是5.3。

This is my function, 这是我的职责

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);
    // ...

}

and I call this function like 我把这个功能叫做

    StartCoroutine (GetFBProfilePicture ());

It works fine in Unity Player and also in Android devices. 它在Unity Player和Android设备中都可以正常工作。 But in iOS devices, "Completed." 但是在iOS设备上,“已完成”。 line doesn't show up. 线不显示。 And there is no error log. 而且没有错误日志。 It just keep waiting in the url line. 它只是在url行中一直等待。

I tried it with iOS 7 and 9 with wireless connection and mobile data. 我在带有无线连接和移动数据的iOS 7和9上进行了尝试。 Problem still occurs. 问题仍然出现。

I just had this same problem, and finally found a solution (albeit, not an ideal one). 我遇到了同样的问题,终于找到了解决方案(尽管不是理想的解决方案)。 Making the request with the parameter redirect=false seems to do the trick, but then it only returns the url for the image, not the image itself. 使用参数redirect = false发出请求似乎可以解决问题,但随后它仅返回图像的url,而不返回图像本身。 So you'll have to make a second request for the image. 因此,您将不得不再次请求该图像。 The following code outlines the solution: 以下代码概述了解决方案:

//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;
    ///...
}

the known issue that recommends the solution: https://developers.facebook.com/x/bugs/364606280347510/ 推荐解决方案的已知问题: https : //developers.facebook.com/x/bugs/364606280347510/

I use this and it works, try it 我用这个就行了,尝试一下

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);
}

the thing is to create a new sprite, not sure why but it works like that 事情是创建一个新的精灵,不确定为什么,但是它像那样工作

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

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