I have been reading Google API and I have learned that I could do two POST requests where first I generate a Bearer token which I later on can do a POST request to add email adress to given folder in Google drive folder.
I have created:
import requests
access_token = requests.post(
'https://www.googleapis.com/oauth2/v4/token',
headers={'content-type': 'application/x-www-form-urlencoded'},
data={
'grant_type': 'refresh_token',
'client_id': 'xxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com',
'client_secret': '07Sxxxxxxxxxxxxxxxx1qpa',
'refresh_token': '1//04xxxxxxxxxxxxxxxxxxxxxxxxxxxs',
}
)
folder_id = "1_5akXx6xB8YighNhtwfI46SO0CI2hiuh"
headers = {
'Authorization': f"Bearer {access_token.json()['access_token']}",
'Accept': 'application/json',
'Content-Type': 'application/json'
}
data = {
"role": "reader",
"type": "user",
"emailAddress": "test@gmail.com"
}
response = requests.post(
f'https://www.googleapis.com/drive/v3/files/{folder_id}/permissions',
headers=headers,
json=data
)
print(headers)
print(response.text)
Which returns:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "internalError",
"message": "Internal Error"
}
],
"code": 500,
"message": "Internal Error"
}
}
By following the guide it seems like I am doing it correct but still it returns Internal error. I wonder what am I doing wrong?