Skip to main content
 首页 » 编程设计

python之验证 Google Store 应用内购买需要哪些权限

2024年11月24日8artech

我正在尝试使用从客户端收到的 token (内部版本)验证用户购买。 为此,我将 Python 脚本与 Google Python API 客户端 ( https://github.com/googleapis/google-api-python-client ) 结合使用。

    import httplib2 
    from oauth2client.service_account import ServiceAccountCredentials 
 
    token = "token received from the client" 
 
    http = httplib2.Http(timeout=self.http_timeout) 
 
    credentials = ServiceAccountCredentials.from_json_keyfile_name( 
        "./service_account.json", "https://www.googleapis.com/auth/androidpublisher" 
    ) 
    http = credentials.authorize(http) 
 
    result = build("androidpublisher", "v3", http=http)\ 
            .purchases()\ 
            .products()\ 
            .get(packageName="<package name>", productId="<subscription id>", token=token)\ 
            .execute(http=http) 

我从这个电话中得到的回应是:

HttpError 401 when requesting https://www.googleapis.com/androidpublisher/v3/applications/<package name>/purchases/products/<subscription id>/tokens/<token>?alt=json returned "The current user has insufficient permissions to perform the requested operation." 

正在使用的服务用户在 Google Play Console 中授予帐户管理员权限(为了测试),并在“Google Cloud Console”控制台中设置为“Project Owner”(为了测试)再次)。

这里似乎出了什么问题?

请您参考如下方法:

“所有者”权限足以进行收据验证 [Source] .

您遇到的错误很可能是传播问题,服务凭证实际上可能需要大约 24 小时才能在整个系统中生效。