PyDrive icon indicating copy to clipboard operation
PyDrive copied to clipboard

localhost isn't an authorized domain

Open panchipanchi opened this issue 5 years ago • 5 comments

no version of localhost works for redirect urls, quickstart is also incorrect there is no web app option to test, create new credentials, existing credentials dont have this issue i suggest you figure out another way to authenticate at least for accessing your own account ie: paste client secret statically into pydrive settings or find an authorized remote domain that redirects to localhost

panchipanchi avatar Aug 20 '19 04:08 panchipanchi

Getting Credentials:

Go Here: Google Console

Login. Create a project if one doesn't already exist (dropdown next to the upper lefthand honeycomb logo). Click Enable APIs and Services. Search for Google Drive; Select it. Click Enable. On Credentials tab, click 'Create Credentials -> Help Me Choose'

Under 'Where will you be calling the API from?': Select Other UI Select User Data Click 'What Credentials do I Need?' Enter a name for the creds. Create OAuth client ID Download creds.

Click Done. You're not done, though.

On the resulting screen, click the download arrow on the far right and save to your working directory. Rename the downloaded file to 'client_secrets.json' (PyDrive people, please fix this to allow for arbitrary names.)

Code to authorize:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from oauth2client.client import GoogleCredentials


gauth = GoogleAuth()
gauth.CommandLineAuth()
#At warning, click Advanced -> Go to PyDrive-Assist
#Follow prompts, paste code back in your cell/commandline.
drive = GoogleDrive(gauth)

Now you're done!

I'm working on a wrapper for all of this over at PyDrive-Assist if you want to check it out! Link here.

mgbvox avatar Sep 05 '19 17:09 mgbvox

i dont want to delete question because u provide helpful info, i may have misplaced a / at end of localhost settings, it does work, so my original question may be obsolete. thanks

panchipanchi avatar Sep 06 '19 02:09 panchipanchi

@mgbvox After I click 'What Credentials do I Need?', I get a prompt to set up an OAuth consent screen. I don't seem to be able to get past this step by entering localhost? How can I circumvent this?

joejoinerr avatar Sep 11 '19 18:09 joejoinerr

@joejoinerr I've actually found more success with GSpread for my purposes - their documentation is enlightening, at least. LINK

RE: PyDrive Assist, I'm refactoring a lot of the code and temporarily made the repo private. Check back in a bit.

mgbvox avatar Sep 12 '19 20:09 mgbvox

I've created a new project and the "Help Me Choose" dialogue ended up creating a "Service account key". After that, I needed to create an "OAuth 2.0 client IDs".

There is a documentation here https://pythonhosted.org/PyDrive/quickstart.html

gnumoksha avatar Nov 24 '19 18:11 gnumoksha