无法获得访问令牌谷歌驱动器sdk

时间:2014-02-28 09:40:52

标签: oauth-2.0 google-drive-api

我想在我的应用程序中使用Google驱动器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.你能告诉我可能是什么问题吗?

1 个答案:

答案 0 :(得分:0)

  1. 跟踪http请求
  2. 转到OAuth2 Playground并执行相同的操作
  3. 发现差异
  4. 可能是你没有对参数进行urlencoding

相关问题