Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Victor_S · Mar 20, 2016 at 07:30 AM · nullreferenceexceptionfacebookdictionary

NullReferenceException: A null value was found where an object instance was required. at InitScript.LoginCallback2

Dear Unity developers, I'm facing a problem with getting id, name and email from Facebook. My code:

 public void CallFBLogin()
     {
         FB.Login("public_profile,email,user_friends", LoginCallback);
     }
 
     private void LoginCallback(FBResult result)
     {
         Debug.Log("LoginCallback");
         if (result.Error != null)
             lastResponse = "Error Response:\n" + result.Error;
         else if (!FB.IsLoggedIn)
         {
             lastResponse = "Login cancelled by Player";
         }
         else
         {
             lastResponse = "Login was successful!";
             
             FB.API("/me?fields=first_name,email,id", Facebook.HttpMethod.GET, LoginCallback2);
         }
     }
     
      void LoginCallback2(FBResult result)
      {
          Debug.Log("LoginCallback2");
          Debug.Log("name responce received " + result.Text);
          
          IDictionary dict = Facebook.MiniJSON.Json.Deserialize(result.Text) as IDictionary;
              fbname = dict["first_name"].ToString();
              
              fbemail = dict["email"].ToString();
              fbid = dict["id"].ToString();
              
              Debug.Log("your name is: " + fbname + " email: " + fbemail + " id = " + fbid);
              
              if (fbemail == null)
              {
                  fbemail = "null@email.com";
              }
              
              RegisterUser(fbid, fbname, fbemail);
      }

RegisterUser method will register player with my backend. When testing in Unity editor with Fb User Token all works great and user registers with my backend. When testing on iOs devise I'm getting an error in XCode:

 NullReferenceException: A null value was found where an object instance was required.
   at InitScript.LoginCallback2 (.FBResult result) [0x00000] in <filename unknown>:0 
   at Facebook.AsyncRequestString+<Start>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0

This code is not mine and I'm actually not native Unity(C#) developer so maybe it's something with Dictionary alloc? Thanks

Comment
Add comment · Show 1
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
avatar image hexagonius · Mar 20, 2016 at 10:45 AM 0
Share

I would check result for null. then I would save the result of the deserialization in a separate variable and log it. then I'd cast it into IDictionary and see if THAT is null.

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

52 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dijkstra shortest path algorithm but i am getting an error; Null reference exception: object reference not set to an instance of an object. 0 Answers

Dictionary not recognising key? 1 Answer

Problem referencing an int inside of a dictionary. 0 Answers

NullReferenceException being thrown when I try to add a component to a dictionary 0 Answers

Trouble with SceneMananger.sceneLoaded and passing dictionaries 0 Answers


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