You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Cloud Print报403 User credentials required错误求助

排查Google Cloud Print API 403 "User credentials required" 问题

我之前也踩过Cloud Print API的403坑,给你几个实际有效的排查方向:

  • 确认Access Token的权限范围
    你用refresh token获取access token的时候,要确保最初授权这个refresh token时,请求的scope包含了https://www.googleapis.com/auth/cloudprint。如果授权时没加这个scope,哪怕refresh token有效,新生成的access token也没有访问Cloud Print的权限。你可以调用Google的Token Info接口验证:

    curl https://oauth2.googleapis.com/tokeninfo?access_token=YOUR_ACCESS_TOKEN
    

    检查返回结果里的scope字段是否包含cloudprint相关的权限。

  • 修正请求方法
    Cloud Print的search接口官方其实是支持GET请求的,你当前用POST可能是问题所在。很多时候API对请求方法有严格限制,换用GET试试:

    $headers = [
        RequestOptions::HEADERS => [
            'Authorization' => 'Bearer ' . $oResponse->access_token,
            'Accept-Charset' => 'utf-8',
        ]
    ];
    
    $getPrinters = $client
        ->get('https://www.google.com/cloudprint/search?output=json', $headers)
        ->getBody()
        ->getContents();
    

    同时可以去掉X-CloudPrint-Proxy头试试,这个头主要用于特定代理场景,普通应用请求可能不需要。

  • 验证Token的有效性
    除了权限范围,还要确认access token没有过期,以及对应的aud(受众)字段和你的client_id一致。如果Token Info返回的expires_in是负数,说明token已经过期,需要重新用refresh token获取新的。

  • 检查测试工具的一致性
    你用Postman或curl测试时,要确保和PHP代码的请求方式、头信息完全一致。比如PHP改成GET后,Postman也用GET请求,并且正确设置Bearer token,不要额外添加多余的头或参数。

如果以上步骤都试过还是不行,建议重新生成refresh token,确保授权流程中明确请求了Cloud Print的权限范围——有时候旧的refresh token可能因为权限变更失效。

内容的提问来源于stack exchange,提问作者naT erraT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:01:31