Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error to parse oauth2 json file for google drive from Alberto Sánchez #17

Closed
kimsama opened this issue Aug 3, 2016 · 4 comments
Closed
Assignees
Labels

Comments

@kimsama
Copy link
Owner

kimsama commented Aug 3, 2016

See the original post below:

Hi again, thank you for helping me out before!

I have another question, I hope you can help!

I am getting an error when I am trying to load a JSON file from console.developers.google.com.

I made GoogleDataSettings.asset, then loaded the JSON file I downloaded, but I can't see the Client ID and the Client Secret on the Inspector, because I get this error:

NullReferenceException: Object reference not set to an instance of an object
UnityQuickSheet.GoogleDataSettingsEditor.OnInspectorGUI () (at Assets/QuickSheet/GDataPlugin/Editor/GoogleDataSettingsEditor.cs:107)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1231)
UnityEditor.DockArea:OnGUI()

Apparently because of this line on GoogleDataSettingsEditor.cs.

var oauthData = JObject.Parse(jsonData).SelectToken("installed").ToString();

I think it is trying to load the data from the token "installed", but it doesn't exist on the JSON file!

Do you know how to solve this so I can verify my account and load data from Google Drive?

Thank you!!

@kimsama
Copy link
Owner Author

kimsama commented Aug 3, 2016

Not sure whether all json files contain "installed" token or not.

I slightly changed the code for parsing and setting OAuth2 information.

original:

    var oauthData = JObject.Parse(jsonData).SelectToken("installed").ToString();
    GoogleDataSettings.Instance.OAuth2Data = JsonConvert.DeserializeObject<GoogleDataSettings.OAuth2JsonData>(oauthData);

changed:

    JObject jo = JObject.Parse(jsonData);
    var propertyValues = jo.PropertyValues();
    foreach (JToken token in propertyValues)
    {
        string val = token.ToString();
        GoogleDataSettings.Instance.OAuth2Data = JsonConvert.DeserializeObject<GoogleDataSettings.OAuth2JsonData>(val);
    }

@kimsama kimsama added the bug label Aug 4, 2016
@kimsama kimsama self-assigned this Aug 4, 2016
@kimsama
Copy link
Owner Author

kimsama commented Aug 4, 2016

Fixed and applied within the googledriver-fix branch

@kimsama
Copy link
Owner Author

kimsama commented Aug 9, 2016

It turned out that json file has wrong format.

@kimsama kimsama closed this as completed Aug 9, 2016
@kimsama
Copy link
Owner Author

kimsama commented Aug 9, 2016

but slightly modified (to parse without 'installed' token) and applied into the googledriver-fix branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant