Facebook SDK: Could not get data from access token: Object reference not set to an instance of an object

I’m sharing something that happened to me in hopes that it saves someone else a lot of time.

I’d been able to call FB.Init() and FB.Login() successfully in my app for many days. All of the sudden I was getting an app stopping error:

Could not get data from access token: Object reference not set to an instance of an object.

I knew the access token is correct. I was able to log it and assign it another variable prior to the error.

I hadn’t changed anything that seems even remotely related.

Answer below!

Doh! Looks like you can’t answer your own questions like on Stack Overflow:

Anyhow, it turns out that this error was triggered by something TOTALLY unrelated. I had the following code after FB.Login() had returned.

AllViewManagerScript.SnapToViewByName("FindFriendViewManager");

The AllViewManagerScriptClass had the following public property and function:

public List<GameObject> viewManagers;


	//move the camera to a view 
	public static void SnapToViewByName(string viewName) {

		foreach (GameObject viewManager in viewManagers){

			if (viewManager.name == viewName){

				//Camera.main.transform.position = new Vector3(viewManager.transform.position.x, Camera.main.transform.position.y, Camera.main.transform.position.z);

			}
		}

	}

I had assigned my view managers via the editor. But then I changed the viewManagers variable to static so that I could access it in my static method. It turns out that this removed the relationships I had previously defined in the editor.

For some reason, the foreach loop would execute once (instead of not at all like you might predict given an empty List), and then created an error when trying to execute the if comparison.

All the above makes reasonable sense as to why it would create an error, but I’m not sure why it would cause the FB SDK to spit out an error that is in fact factually related.

Point is, if you’re getting the above error, you may have nothing wrong with your FB specific code.