8

我想从我的 webServer 调用 Google 云打印的 /search 方法。

我正在使用 OAuth Web 服务器指南获取用于范围的 refresh_token/access_token:

https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile

然后我打电话给搜索 Api,但我得到了 403 禁止。

    Request DefaultHttpRequest(chunked: false)
    POST /cloudprint/search HTTP/1.1
    Host: www.google.com
    Content-Type: text/plain; charset=utf-8
    Authorization: OAuth yb29.1.AADtN_U9PYyVhGpcS-8MpFhfGVbT4KsZKEoIX2HGePwoNXypjrSwVsS0pGzmaqhktfGBAQ
    Connection: keep-alive
    Accept: */*
    User-Agent: NING/1.0
    Content-Length: 0

    Response DefaultHttpResponse(chunked: true)
    HTTP/1.1 403 Forbidden
    Content-Type: text/html; charset=utf-8
    Cache-Control: no-cache, no-store, max-age=0, must-revalidate
    Pragma: no-cache
    Expires: Fri, 01 Jan 1990 00:00:00 GMT
    Date: Tue, 03 Dec 2013 17:05:09 GMT
    Set-Cookie: NID=67=MQJFdl-YkMdz875n1J2yVNmeUeAvsjVtDGlNvGkNLZdNTHX3YbnStNx9Vg_MiRsmht6hj3XrwJcPJEQeFLlnYKqt2Of1xHJ5HDwNJgOB3svOdnN-JRFcPxYt4AU10eSM;Domain=.google.com;Path=/;Expires=Wed, 04-Jun-2014 17:05:09 GMT;HttpOnly
    P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
    X-Content-Type-Options: nosniff
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    Server: GSE
    Alternate-Protocol: 443:quic
    Transfer-Encoding: chunked

范围是否正确?我究竟做错了什么?

4

2 回答 2

5

你的范围是错误的。正确的范围是https://www.googleapis.com/auth/cloudprint

于 2016-02-24T17:23:36.883 回答
0

我认为这与您的 HTTP 标头“授权”有关。

https://developers.google.com/oauthplayground/玩游戏时,我看到生成的请求使用“授权:承载你的令牌”,而不是“授权:OAuth 你的令牌”。

于 2013-12-03T18:01:05.543 回答