且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何直接使用curl获取Google OAuth 2.0访问令牌? (不使用Google库)

更新时间:2023-02-16 08:29:43

a)您提供的数据应采用表单编码表示为JSON对象,并且b)您还应该在 code参数中提供授权码值。例如:

a) the data you provide should be form-encoded instead of presented as a JSON object and b) you should also provide an authorization code value in the "code" parameter. E.g.:

curl -d "client_id=MY_CLIENT_ID&\
  client_secret=MY_SECRET_KEY&\
  redirect_uri=http://localhost/etc&\
  grant_type=authorization_code&\
  code=CODE" https://oauth2.googleapis.com/token