Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Facebook.MiniJSON;
- FB.API (GetPictureURL(user["id"].ToString(), 128,128), Facebook.HttpMethod.GET, delegate(FBResult pictureResult)
- {
- string imageUrl = DeserializePictureURLString(pictureResult.Text);
- StartCoroutine(LoadPictureEnumerator(imageUrl,pictureTexture =>
- {
- UserAvatar.sprite = Sprite.Create (pictureTexture, new Rect(0,0,128,128), new Vector2(0,0));
- }));
- });
- delegate void LoadPictureCallback (Texture2D texture);
- IEnumerator LoadPictureEnumerator(string url, LoadPictureCallback callback)
- {
- WWW www = new WWW(url);
- yield return www;
- callback(www.texture);
- }
- public string DeserializePictureURLString(string response)
- {
- return DeserializePictureURLObject(Json.Deserialize(response));
- }
- public string DeserializePictureURLObject(object pictureObj)
- {
- var picture = (Dictionary<string, object>)(((Dictionary<string, object>)pictureObj)["data"]);
- object urlH = null;
- if (picture.TryGetValue("url", out urlH))
- {
- return (string)urlH;
- }
- return null;
- }
- private string GetPictureURL(string facebookID, int? width = null, int? height = null, string type = null)
- {
- string url = string.Format("/{0}/picture", facebookID);
- string query = width != null ? "&width=" + width.ToString() : "";
- query += height != null ? "&height=" + height.ToString() : "";
- query += type != null ? "&type=" + type : "";
- query += "&redirect=false";
- if (query != "") url += ("?g" + query);
- return url;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement