I want to make an installed aplication in Python3 to manage the Google Drive files in my google account.
As the official google-api-python-client doesn't support Python3 I've decided to code myself the oauth2 method and access to google drive api with urlib.request.
I managed to pass the authentication process and get the token. Then I tried to access to the google drive api (copying a file) following the api reference: POST https://www.googleapis.com/drive/v2/files/fileId/copy with this code:
def copy_file(token, target_name):
print("Access Token: " + token)
url_target = "https://www.googleapis.com/drive/v2/files/0Akg4S5DP95FAdFM3VXNJbVo4TjM0MFFGVm5hWlFtU2c/copy"
request = urllib.request.Request(url_target)
request.add_header("Authorization", "OAuth" + token)
request.add_header("title", target_name)
f = urllib.request.urlopen(request)
print(f.read())
I only get 404 error.
When I try with the Google Api Explorer it work ok:
Request
POST https://www.googleapis.com/drive/v2/files/0Akg4S5DP95FAdFM3VXNJbVo4TjM0MFFGVm5hWlFtU2c/copy?key={YOUR_API_KEY}
Content-Type: application/json
Authorization: Bearer ya29.1.AADtN_ULTFZ3jvv962bVVjAYv_GknktRMgvIGAGJPdZ5OAocQANLmN5q_UMq5cA53aqoHBkqo39wHiGM1-pg
X-JavaScript-User-Agent: Google APIs Explorer
{
"title": "copia de HiperAgenda"
}
Response
200 OK
I've omitted in my code this ?key={YOUR_API_KEY} Where is my Api Key?
What's my wrong?