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

使用PHP google/apiclient获取Google Play应用评论时遭遇401认证错误的求助

使用PHP google/apiclient获取Google Play应用评论时遭遇401认证错误的求助

大家好,我最近在做一个小项目,想通过PHP获取我的Android应用在Google Play商店的用户评论,需要展示评论者名称、评论日期和评分。但现在卡在了认证环节,一直收到401 Unauthorized错误,折腾好几天都没解决,来这儿求助各位大佬!

先说说我的配置情况:

  • 我用的是Google Cloud平台的OAuth 2.0 Client IDs做身份验证
  • PHP项目通过Composer引入了google/apiclient包,版本是^2.15.0,我的composer.json配置如下:
{
    "name": "app/reviews",
    "description": "A project to fetch Google Play Store reviews using PHP",
    "require": {
        "google/apiclient": "^2.15.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    }
}
  • 我的凭据文件credentials.json是Web类型的,内容大概是这样的(敏感信息打码了):
{
   "web":{
      "client_id":"******-********.apps.googleusercontent.com",
      "project_id":"****-****-373117",
      "auth_uri":"https://accounts.google.com/o/oauth2/auth",
      "token_uri":"https://oauth2.googleapis.com/token",
      "auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"
      // 其他相关字段已省略
   }
}

我按照官方文档的步骤初始化了Google客户端,加载了凭据文件,但调用Google Play Developer API的评论查询接口时,每次都返回401错误。我已经确认过:

  • 客户端ID和项目ID都是对应正确的
  • Google Play Developer API已经在Google Cloud控制台开启了
  • 凭据文件也没有配置错误

想问问大家,有没有遇到过类似的问题?可能是哪里出了问题呢?比如是不是OAuth的授权流程选错了?还是我应该用服务账号而不是OAuth 2.0 Web客户端?麻烦各位给点思路,谢谢啦!

备注:内容来源于stack exchange,提问作者Moahemd Abdelkhalel

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.16 09:44:50