Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by LAFI · Jun 18, 2015 at 06:22 AM · c#texturefacebookui imagedeserialize

i want to get all facebook user photos

i want to get all user photos from facebook, then display Them into scene I tried several times, but I have no result. Ihave no error in my code, when i enter in play mode nothing happen. Please i need your help Thank you in advance

these are my two scripts:

the first script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Facebook.MiniJSON;
 
 public class Util : ScriptableObject
 {
     public static 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 : "";
         if (query != "") url += ("?g" + query);
         return url;
     }
 
     public static void FriendPictureCallback(FBResult result)
     {
         if (result.Error != null)
         {
             Debug.LogError(result.Error);
             return;
         }
 
         
     }
 
     public static Dictionary<string, string> RandomFriend(List<object> friends)
     {
         var fd = ((Dictionary<string, object>)(friends[Random.Range(0, friends.Count - 1)]));
         var friend = new Dictionary<string, string>();
         friend["id"] = (string)fd["id"];
         friend["first_name"] = (string)fd["first_name"];
         return friend;
     }
 
     public static Dictionary<string, string> DeserializeJSONProfile(string response)
     {
         var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
         object nameH;
         var profile = new Dictionary<string, string>();
         if (responseObject.TryGetValue("first_name", out nameH))
         {
             profile["first_name"] = (string)nameH;
         }
         return profile;
     }
     
     public static List<object> DeserializeScores(string response) 
     {
 
         var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
         object scoresh;
         var scores = new List<object>();
         if (responseObject.TryGetValue ("data", out scoresh)) 
         {
             scores = (List<object>) scoresh;
         }
 
         return scores;
     }
 
     public static List<object> DeserializeJSONFriends(string response)
     {
         var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
         object friendsH;
         var friends = new List<object>();
         if (responseObject.TryGetValue("friends", out friendsH))
         {
             friends = (List<object>)(((Dictionary<string, object>)friendsH)["data"]);
         }
         return friends;
     }
 
 
     public static List<object> DeserializeJSONAllPictures(string response)
     {
         var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
         object PicturesH;
         var Pictures = new List<object>();
         if (responseObject.TryGetValue ("Pictures", out PicturesH)) 
         {
             Pictures = (List<object>)(((Dictionary<string,object>)PicturesH)["data"]);
         }
         return Pictures;
     }
     
     public static void DrawActualSizeTexture (Vector2 pos, Texture texture, float scale = 1.0f)
     {
         Rect rect = new Rect (pos.x, pos.y, texture.width * scale , texture.height * scale);
         GUI.DrawTexture(rect, texture);
     }
     public static void DrawSimpleText (Vector2 pos, GUIStyle style, string text)
     {
         Rect rect = new Rect (pos.x, pos.y, Screen.width, Screen.height);
         GUI.Label (rect, text, style);
     }
 }

The second script:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using Facebook;
 public class FacbookHolder : MonoBehaviour {
     public GameObject Picture;
     void Awake()
     {
         FB.Init (SetInit, onHideUnity);
     }
 
     private void SetInit()
     {
         Debug.Log("FB Init Done");
         if (FB.IsLoggedIn) {
             Debug.Log ("FB lOGGED iN");
         }else {
             //FBLogin();
         }
     }
 
     
     private void onHideUnity(bool isGameShown)
     {
         if (!isGameShown) {
             Time.timeScale = 0;
         } else 
         {
             Time.timeScale = 1;
         }
     }
     public void FBLogin()
     {
         FB.Login ("email", AuthCallback);
     }
     void AuthCallback(FBResult result)
     {
         if (FB.IsLoggedIn) {
             Debug.Log ("user logged in");
         } else {
             Debug.Log("login failed");
         }
     }
     void GetPicture()
     {
         if (FB.IsLoggedIn) {
             FB.API(Util.GetPictureURL("me",100,100) , Facebook.HttpMethod.GET, ProfilePicture);
         }
     }
     void ProfilePicture(FBResult result)
     {
         if (result.Error != null) {
             Debug.Log ("Problem with profile picture");
             FB.API (Util.GetPictureURL ("me", 100, 100), Facebook.HttpMethod.GET, ProfilePicture);
             Debug.Log ("picture");
             return;
         } else {
             Debug.Log("errrooooooooooorrrrr");
         }
         Image UserPicture = Picture.GetComponent<Image> ();
         UserPicture.sprite = Sprite.Create (result.Texture, new Rect (0, 0, 100, 100), new Vector2 (0, 0));
     }
 
      void GetUserPictures()
     {
         if (FB.IsLoggedIn) {
             FB.API(Util.GetPictureURL("/me/photos/uploaded",100,100) , Facebook.HttpMethod.GET, Photos);
             return;
         }
         // void Photos() ?????
             // how to load Them into scene
              
     }
 
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Sprite image not showing up when assigned to Texture2D 0 Answers

Material Not Reverting Back 2 Answers

Animated Texture Offset 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges