Posted By

abrady0 on 09/03/13


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

danfinrud55


FBUtil.cs


 / Published in: C#
 

missing fb sdk code

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class FBUtil : ScriptableObject
  6. {
  7.  
  8. public static string GetPictureURL(string facebookID, int? width = null, int? height = null, string type = null, bool secure = true)
  9. {
  10. string url = "https://graph.facebook.com/" + facebookID + "/picture";
  11. string query = width != null ? "&width=" + width.ToString() : "";
  12. query += height != null ? "&height=" + height.ToString() : "";
  13. query += type != null ? "&type=" + type : "";
  14. query += "&access_token=" + FB.AccessToken;
  15. if (query != "") url += ("?g" + query);
  16. return url;
  17. }
  18.  
  19. public static IEnumerator GetFriendPictureTexture(string facebookID, int width = 128, int height = 128, string type = null, bool secure = true)
  20. {
  21. string url = GetPictureURL(facebookID, width, height, type, secure);
  22. WWW www = new WWW(url);
  23. yield return www;
  24. GameStateManager.FriendTexture = www.texture;
  25. }
  26.  
  27. public delegate void TextureCallback(Texture tex);
  28.  
  29. public static IEnumerator GetPictureTexture(string facebookID, int width = 128, int height = 128, string type = null, bool secure = true, TextureCallback callback = null)
  30. {
  31. string url = GetPictureURL(facebookID, width, height, type, secure);
  32. WWW www = new WWW(url);
  33. yield return www;
  34. callback(www.texture);
  35. }
  36.  
  37. public static Dictionary<string, string> RandomFriend(List<object> friends)
  38. {
  39. var fd = ((Dictionary<string, object>)(friends[Random.Range(0, friends.Count - 1)]));
  40. var friend = new Dictionary<string, string>();
  41. friend["id"] = (string)fd["id"];
  42. friend["first_name"] = (string)fd["first_name"];
  43. return friend;
  44. }
  45.  
  46. public static Dictionary<string, string> DeserializeJSONProfile(string response)
  47. {
  48. var responseObject = MiniJSON.Json.Deserialize(response) as Dictionary<string, object>;
  49. object nameH;
  50. var profile = new Dictionary<string, string>();
  51. if (responseObject.TryGetValue("first_name", out nameH))
  52. {
  53. profile["first_name"] = (string)nameH;
  54. }
  55. return profile;
  56. }
  57.  
  58. public static List<object> DeserializeJSONFriends(string response)
  59. {
  60. var responseObject = MiniJSON.Json.Deserialize(response) as Dictionary<string, object>;
  61. object friendsH;
  62. var friends = new List<object>();
  63. if (responseObject.TryGetValue("friends", out friendsH))
  64. {
  65. friends = (List<object>)(((Dictionary<string, object>)friendsH)["data"]);
  66. }
  67. return friends;
  68. }
  69. }

Report this snippet  

You need to login to post a comment.