【问题标题】:Can't get access token google drive sdk无法获取访问令牌 google drive sdk
【发布时间】:2014-02-28 09:40:52
【问题描述】:

我想在我的应用程序中使用 Google drive api,这就是我将 OAuth 2.0 用于已安装应用程序的原因。但我有一个问题 - 我无法获得访问令牌。起初我使用以下请求成功获得了授权码:

  https://accounts.google.com/o/oauth2/auth?
  scope=https://www.googleapis.com/auth/drive.file&
  redirect_uri=[my redirect_uri from from Developers Console]&
  response_type=code&
  client_id=[My client ID for native application from Developers Console]

然后我尝试通过以下请求使用收到的授权代码获取访问令牌:

   POST /o/oauth2/token HTTP/1.1
   Host: accounts.google.com
   Content-Type: application/x-www-form-urlencoded

   code={My uthorization code}&
   client_id=[My client Id]&
   client_secret=[My clien secret]&
   redirect_uri=[my redirect_uri from from Developers Console]&
   grant_type=authorization_code

服务器总是返回 400。你能告诉我可能是什么问题吗?

【问题讨论】:

    标签: oauth-2.0 google-drive-api


    【解决方案1】:
    1. 跟踪 http 请求
    2. 转到 OAuth2 Playground 并执行相同操作
    3. 发现差异

    可能是您没有对参数进行 urlencoding

    【讨论】:

      猜你喜欢
      • 2017-07-30
      • 2013-02-22
      • 2014-04-11
      • 1970-01-01
      • 2020-12-11
      • 2015-02-11
      • 1970-01-01
      • 2020-06-12
      • 2015-04-09
      相关资源
      最近更新 更多