Thanks to this guy, whose question and gist helps me understand the google api and requests for it to get access for google drive.
I found everything!
If anybody will be confused like me:
Get your google drive your_api_key from here:
- https://console.developers.google.com/apis/credentials?project=[your_project]
in section with name “API keys” – or you can generate it by pushing “New Credentials” -> “API key”
Also you can get your token with google “quick start” even for python3:
Your token will be saved on system user’s folder (C:/Users/user/.credentials) or (/root/.credentials) for Linux if you run it under “root”. The token is in “access_token” key value.
Then you can generate request, but at first check this: http://docs.python-requests.org/en/master/user/quickstart/#custom-headers
And this is working example to get list of your google drive files:
import requests token = '<THAT_TOKEN_FROM_YOUR_FILE_FROM_USERS_DIR>' url = "https://www.googleapis.com/drive/v2/files?key=" key = "<THAT_KEY_WHICH_YOU_GENERATE_ON_GOOGLE_API_CONSOLE>" header = {'Authorization':"Bearer " + token} list_files = requests.get(url+key, headers=header) answer = list_files.json() print(answer)
Attention!
Token is expiring very soon!
https://developers.google.com/identity/protocols/OAuth2UserAgent#handlingtheresponse
Для русскоязычных ребят ключевое слово: google api key получить
Curl example from docs:
Examples
A call to the drive.files
endpoint (the Drive API) using the access_token
query string parameter might look like the following, though you’ll need to specify your own access token:
GET https://www.googleapis.com/drive/v2/files?access_token=1/fFBGRNJru1FQd44AzqT3Zg
Here is a call to the same API for the authenticated user (me
) using the Authorization: Bearer
HTTP header:
GET /drive/v2/files HTTP/1.1 Authorization: Bearer 1/fFBGRNJru1FQd44AzqT3Zg Host: googleapis.com
You can try out with the curl
command-line application. Here’s an example using the HTTP header option (preferred):
curl -H "Authorization: Bearer 1/fFBGRNJru1FQd44AzqT3Zg" https://www.googleapis.com/drive/v2/files
Or, alternatively, the query string parameter option:
curl https://www.googleapis.com/drive/v2/files?access_token=1/fFBGRNJru1FQd44AzqT3Zg