upload fail the google api after redirecting to localhost - google-drive-api

After I run the following code from:
https://developers.google.com/drive/api/v3/quickstart/python
I get the link:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=792377765624-8l03cnfmj1km5gd27227kuaem37okdip.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A41245%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly&state=8xHuMrgWMisZa7Hww6HpIZrRdkRTjq&access_type=offline
I click it and get new pages.
I was not allowed to upload pictures here,sorry.
Because my score is low in stackoverflow
Finally, it tell me I can not connect to:
http://localhost:44637
Screenshots of the behaviour: https://blog.csdn.net/appleyuchi/article/details/102940981

According to the screenshots you provided and the url you are getting redirected to, the problem is that the Google account with which you downloaded the credentials file is not the same as the one with which you grant authorization to Drive. Both should be the same, because the credentials file contains information that identifies the account that downloaded them.
Check these for further information on the authentication process:
https://developers.google.com/identity/protocols/OAuth2
https://developers.google.com/identity/protocols/OAuth2WebServer

Related

How can I restore permissions for Chrome to access any local files from VS Code?

Now, every time I try to open my html file in my Chrome browser, I get this message:
ERR_ACCESS_DENIED
Can someone please tell me how I can reverse this?
How do I grant Chrome the permission to access any local files on my VS Code and atom?
Now, Thanks to Kuma, check out the thread link he or she provided, which helped me. You just have to go to system preferences, and under security and privacy, go to filers and folders, and go to files and folders and check the check box next to chrome.
If you are on a Mac, you can try the following:
Run the the following command on the file in a terminal, then try to open it again:
xattr 'your .html file name'
# If it shows com.apple.quarantine, run
xattr -c 'your html file name'
If that fixes it then it's most likely some apple security metadata on the file that get attached when files are downloaded from the web.
If you are on Windows10, you can view all the permissions you have added and rejected for an app (see this link: https://www.google.com/amp/s/www.howtogeek.com/368598/how-to-manage-app-permissions-on-windows-10/amp/)
Extract:
From the Settings screen, you can head to Settings > Apps > Apps & Features, click an app, and click “Advanced Options.”
Scroll down, and you’ll see the permissions the app can use under “App Permissions.” Toggle the app permissions on or off to allow or disallow access.
Otherwise, knowing what OS you are using will help find a solution.
There is also this other stack overflow thread, so you can try some of the answers there: Can't open some html files in chrome (mac)

what client_secret.json file is it required for google drive files access

I am getting this error:
File "/usr/local/lib/python3.7/site-packages/pydrive/auth.py", line 388, in LoadClientConfigFile
raise InvalidConfigError('Invalid client secrets file %s' % error)
pydrive.settings.InvalidConfigError: Invalid client secrets file ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)
all I want is to list files and folders using pydrive !
I tried creating credentials but On consent page its showing unverified status.
from the credential page under OAuth 2.0 Client IDs tab I downloaded created credentials and downloaded crediential file secret_json_[.....].json file
Looking into the documentation for pyDrive:
Click ‘Download JSON’ on the right side of Client ID to download client_secret_<really long ID>.json.
The downloaded file has all authentication information of your application. Rename the file to client_secrets.json and place it in your working directory.
So probably you are lacking the last step of renaming the file and placing it in the working directory.
I tried creating credentials but On consent page its showing unverified status.
This should not matter at all, unverified just means that you are trying to access sensitive scopes and until Google verifies your application there would be an extra screen indicating that it is a unverified apps. Is okay for personal/development use.

Reauthenticate or Remove authentication Pydrive during runtime in Google Colab

I want to reauthenticate my Google Drive Credentials so that I can login from a different Google account and access it using pydrive. How can I do that?
I am using the following code to authenticate:
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(auth = gauth)
I want to get a fresh token and option to login again into a different google account?
Thanks for helping!
Try deleting the credential file produced by auth.authenticate_user() based on the auth module
rm /content/adc.json
I have just found a solution to this issue. If one goes to his/hers Google Account Settings->Security->Signing in to other sites(all the way down)->YOUR PROCESS NAME and then simply remove it. If you try simply listing the files in the authenticated drive again it should fail with "Token has been expired or revoked."
Just make sure when you create and enter your correct account credentials to delete the credentials/client_secret.json file as the settings.yaml does not seem to overwrite
To reset credentials just remove the gdrive config folder with a shell command from a code block
rm ~/.config/Google/DriveFS/ -rf
I ran into a similar problem where I clicked on the wrong account for Google Drive authentication. None of the files I needed to access were available, and I couldn't figure out a way to revoke a token by the comments above. I tried both restarting the runtime and changing from GPU to TPU. When I tried the latter, it worked and the authorization prompt returned. However, I'm not sure if it worked or just reached the token refresh time.
I factory reset my runtime and was able to get it to accept a different credential.
Runtime -> factory reset runtime

google drive hosting after browser got 404 error

I have create a new website using bootstrap.
I want to host it in googledrive.
I have upload my project folder in googledrive. then share option change to public. i have copy to the folder id
now browser ip googledrive.com/host/folder_id/index.html
But browser was showing
404 error
The requested URL /host/0B8EDhQEMaanYcnF2T2JEUGRQdWc was not found on this server.
Please some one help me how to host it on googledrive.

Google Drive DriveCommandLine sample app not working?

Is the Google Drive API sample command line app (DriveCommandLine) currently known to work? I have downloaded the Java client library, and compiled the sample application (inserting my application's client ID and secret created by specifying "installed application" and "other"). It runs and informs me to access the following link in a browser:
https://accounts.google.com/o/oauth2/auth?access_type=online&approval_prompt=auto&client_id=MY_ACTUAL_CLIENT_ID&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive
(Obviously with my actual client ID there.)
This successfully provides me with an authentication code. When I enter this at the application's prompt, then at the line:
File file = service.files().insert(body, mediaContent).execute();
I get the exception:
Exception in thread "main" com.google.api.client.http.HttpResponseException: 401 Unauthorized
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:978)
at com.google.api.client.googleapis.media.MediaHttpUploader.executeUploadInitiation(MediaHttpUploader.java:338)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:252)
at com.google.api.services.drive.Drive$Files$Insert.executeUnparsed(Drive.java:309)
at com.google.api.services.drive.Drive$Files$Insert.execute(Drive.java:331)
at DriveCommandLine.main(DriveCommandLine.java:56)
Investigation shows that the GoogleCredential returned has all elements set to null (which seems wrong).
The version of the Drive API client that I am using is "v2-rev5-1.7.2-beta", which is the one currently pointed to on the quickstart page here:
https://developers.google.com/drive/quickstart
I am compiling and running with this JAR and all the ones in the "libs" subdirectory in the classpath (the quickstart page refers to adding source JARs to the classpath which, obviously, dosn't work).
Can anyone shed any light on what might be going wrong here?
Thanks!
The link in the Quick Start is outdated. Try downloading the Drive SDK from the following link: http://code.google.com/p/google-api-java-client/wiki/APIs#Drive_API
See if that makes a difference for you. I have the DriveCommandLine app running fine.
You need to download JSON file from the API access page at
https://cloud.google.com/console.
Rename this json file as "client_secrets.json"
Copy this json into your project folder or more specifically copy it
into "src/main/resources". (This file contains the clientID and secrets). If the file is already present in the folder then replace it.
Now run the project. You will be redirect to Google Drive's "allow
access" page.
PS - json file must belong to an "Installed Type Application" because this is a commandline sample and runs locally.