为什么Google Calendar API不接受我的不记名令牌?

时间:2014-03-18 19:36:49

标签: oauth-2.0 authorization google-calendar-api bearer-token

我正在尝试通过使用Firefox 28.0和REST Client v2.0.3进行Google API调用来学习OAuth 2.0。

  1. 我访问了Google Developer OAuth 2.0 Playground网站。
  2. 我使用Google凭据登录
  3. 选择“Calendar API v3”.readonly
  4. 点击“授权API”按钮
  5. 然后我点击了“令牌的Exchage授权码”并获得了访问令牌ab31.4.CDEfG_HI1JkKMNoPQR5S9tuvW_x2yzabcDEFGhiJklMnOpqRs-T6uvwXyza5BcdEFGHiJK3L
  6. Calendar API开始,我使用GET HTTP操作的网址https://www.googleapis.com/calendar/v3/users/me/calendarList
  7. 在RESTClient中,我创建一个名为“Authorization”的标头,并将值ab31.4.CDEfG_HI1JkKMNoPQR5S9tuvW_x2yzabcDEFGhiJklMnOpqRs-T6uvwXyza5BcdEFGHiJK3L设置为来自OAuth 2.0 Playground的“访问标记:”框。
  8. Body我点击SEND我收到授权错误(操场上说我的令牌仍有效30分钟)
  9. 错误的标题是:

    Status Code: 401 Unauthorized
    Alternate-Protocol: 443:quic
    Cache-Control: private, max-age=0
    Content-Encoding: gzip
    Content-Length: 162
    Content-Type: application/json; charset=UTF-8
    Date: Tue, 18 Mar 2014 19:17:35 GMT
    Expires: Tue, 18 Mar 2014 19:17:35 GMT
    Server: GSE
    WWW-Authenticate: Bearer realm="https://www.google.com/accounts/AuthSubRequest"
    X-Content-Type-Options: nosniff
    X-Firefox-Spdy: 3.1
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    

    身体是:

    {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "authError",
        "message": "Invalid Credentials",
        "locationType": "header",
        "location": "Authorization"
       }
      ],
      "code": 401,
      "message": "Invalid Credentials"
     }
    }
    

1 个答案:

答案 0 :(得分:0)

标题需要设置为Authorization: Bearer ab31.4.CDEfG_HI1JkKMNoPQR5S9tuvW_x2yzabcDEFGhiJklMnOpqRs-T6uvwXyza5BcdEFGHiJK3L。你需要" Bearer"在令牌之前。