谷歌云打印获取访问令牌

8

我想从我的Web服务器调用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

这个范围是否正确? 我做错了什么?

2个回答

5

您的范围不正确。正确的范围是https://www.googleapis.com/auth/cloudprint


谢谢@EvanC,你能提供这个来源的链接吗?我在谷歌文档中找不到。 - Josh Mc
1
@JoshMc https://developers.google.com/identity/protocols/OAuth2ForDevices#allowedscopes - EvanC

0

我认为这与你的HTTP头部'Authorization'有关。

当在https://developers.google.com/oauthplayground/上进行操作时,我发现生成的请求使用的是'Authorization: Bearer your-token',而不是'Authorization: OAuth your-token'。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接