import requests
url = "https://translation.googleapis.com/v3beta1/projects/p*******3/locations/global:translateText"
token = "4/xAG_QxNqxN5IlNPx96ge******nM5mSmWt8lGZY0Zv-j1Wom196DFQ"
headers = {"Authorization": "Bearer " + token,
"Content-Type": "application/json; charset=utf-8"}
data = {
"model": "projects/p*******3/locations/global/models/general/base",
"sourceLanguageCode": "en",
"targetLanguageCode": "de",
"contents": ["Come here!"]
}
res = requests.post(url, headers=headers, data=data)
print(res.text)
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}