Python DrEdit example for Google Drive API throws 500 error

I'm having trouble with the Python version of DrEdit on Google App Engine. It works fine when accessed from drive.google.com, but when I try to open it from the .appspot.com address, I get a 500 error.

The error message shows a JSONDecodeError, saying "No JSON object could be decoded". I added a print statement to check the 'state' parameter, but it just returns some headers instead of the expected JSON data.

Here's what I've tried so far:
1. Deployed the app to GAE
2. Tested it from drive.google.com (works fine)
3. Tried accessing it directly from .appspot.com (gets the error)
4. Added debug print statements

I'm not sure what's causing this issue or how to fix it. Any ideas on what I should check next? Has anyone else run into this problem with the DrEdit example?

hey, i ran into this too. the state param is empty when u go straight to appspot url. try adding a check for that in ur code. maybe redirect to an error page if its missing. also, make sure ur using latest google api client lib. old versions can be wonky with auth stuff.

I’ve dealt with this issue in my own projects. The problem lies in how the app handles authentication when accessed directly. The state parameter is crucial for OAuth flow, but it’s not present when you bypass Google Drive.

To resolve this, I’d suggest implementing a fallback mechanism in your code. Check if the state parameter exists, and if not, redirect to a login page or display a message explaining the app should be accessed via Google Drive.

Also, ensure your app’s configuration in the Google Cloud Console is correct. Verify the authorized redirect URIs include your .appspot.com domain. This can sometimes cause unexpected authentication issues.

Lastly, consider using the Google Sign-In for Websites flow as an alternative authentication method for direct access. This might provide a more robust solution for your use case.

I have encountered a similar issue before with the DrEdit example. When accessing the app directly from the .appspot.com URL, the state parameter does not receive the necessary authentication details that are automatically provided by drive.google.com. In my experience, double-checking the OAuth settings in the Google Cloud Console and ensuring that the client_secrets.json is up-to-date can help identify the problem. It may also be beneficial to add more detailed error logging in your code to better handle cases where the state parameter is missing or invalid. Keep in mind that this example is primarily designed for use within Google Drive, so adjustments may be needed for direct access.