Is it possible to generate the downloadable link for a private file uploaded in the google drive?
I have tried with the files API and generated the 'webContent Link', but it is accessible only to the owner and the shared users.
(Expecting a public link that can be shared with anyone)
def file_info_drive(access_token, file_id):
headers = {'Authorization': 'Bearer ' + access_token, "content-type": "application/json"}
response = requests.get('https://www.googleapis.com/drive/v2/files/{file_id}', headers=headers)
response = response.json()
link = response['webContentLink']
return link
webContentLink
.If my understanding is correct, how about this modification?
webContentLink
, it is required to share publicly the file.
{'role': 'reader', 'type': 'anyone', 'withLink': True}
. In this case, the persons who know the URL can download the file.When your script is modified, it becomes as follows.
def file_info_drive(access_token, file_id):
headers = {'Authorization': 'Bearer ' + access_token, "content-type": "application/json"}
# Using the following script, the file is shared publicly. By this, anyone can download the file.
payload = {'role': 'reader', 'type': 'anyone', 'withLink': True}
requests.post('https://www.googleapis.com/drive/v2/files/{file_id}/permissions', json=payload, headers=headers)
response = requests.get('https://www.googleapis.com/drive/v2/files/{file_id}', headers=headers)
response = response.json()
link = response['webContentLink']
return link
https://www.googleapis.com/auth/drive
to the scope.If I misunderstood your question and this was not the direction you want, I apologize.