使用Curl将文件上载到Google Drive

使用Curl将文件上载到Google Drive,curl,oauth,google-api,google-drive-api,google-oauth,Curl,Oauth,Google Api,Google Drive Api,Google Oauth,我正在尝试使用Curl将本地系统上的文件上载到我的google drive帐户。我转到Google开发者控制台,启用了Google Drive API,创建了一个API-KEY

我正在尝试使用
Curl
将本地系统上的文件上载到我的google drive帐户。我转到Google开发者控制台,启用了Google Drive API,创建了一个
API-KEY
<这是我的卷发要求

curl -X POST -L \
    -H "Authorization: Bearer my_API-KEY" \
    -F "metadata={name : 'JUMBA'};type=application/json;charset=UTF-8" \
    -F "file=@my_file.json;type=application/zip" \
    "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
但我得到了这个错误-

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}
文件也不是很清楚。有人帮忙吗

“授权:我的API-KEY持有人”

授权标头应包含承载令牌。承载令牌是JWT访问令牌。api密钥是仅用于访问公共数据的公钥。您需要完成授权过程并请求访问令牌,然后才能执行此操作

# Client id from Google Developer console
# Client Secret from Google Developer console
# Scope this is a space seprated list of the scopes of access you are requesting.

# Authorization link.  Place this in a browser and copy the code that is returned after you accept the scopes.
https://accounts.google.com/o/oauth2/auth?client_id=[Application Client Id]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=[Scopes]&response_type=code

# Exchange Authorization code for an access token and a refresh token.

curl \
--request POST \
--data "code=[Authentcation code from authorization link]&client_id=[Application Client Id]&client_secret=[Application Client Secret]&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" \
https://accounts.google.com/o/oauth2/token

# Exchange a refresh token for a new access token.
curl \
--request POST \
--data 'client_id=[Application Client Id]&client_secret=[Application Client Secret]&refresh_token=[Refresh token granted by second step]&grant_type=refresh_token' \
https://accounts.google.com/o/oauth2/token

让我知道如果你有任何问题,改变谷歌驱动器。您也可以检查我对这个相关问题的回答

API密钥不能用作访问令牌。而且,API密钥不能用于POST和PUT方法。API密钥可用于使用GET方法请求公共共享内容。例如,使用OAuth2和/或服务帐户检索的访问令牌怎么样?@Tanaike-ah好的。所以我应该转到OAuth咨询屏幕并添加google drive
auth/drive
scope?但它要求一个强制性的主页url、隐私政策url等。我只是想通过编程将文档上传到我的谷歌硬盘。我没有隐私政策的url和主页谢谢你的回复。我注意到现在已经发布了答案。我认为这会解决你的问题。