【问题标题】:How do I access Google Playstore API to get reviews of our app using Python script?如何使用 Python 脚本访问 Google Playstore API 以获取对我们应用程序的评论?
【发布时间】:2021-03-20 22:01:27
【问题描述】:

我有一个服务帐户和为该应用程序帐户生成的私钥。

testxyz.json - 包含私钥和服务帐户信息。

这是脚本:

from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
import ssl
import json

ssl._create_default_https_context = ssl._create_unverified_context


credentials = ServiceAccountCredentials.from_json_keyfile_name('testxyz.json',scopes=['https://www.googleapis.com/auth/androidpublisher'])


http = httplib2.Http()
http = credentials.authorize(http)
service = build('androidpublisher', 'v3', http=http)
print(service)

package_name = "xtestx"
reviews_resource = service.reviews()
print(reviews_resource)
reviews_page = reviews_resource.list(packageName=package_name,maxResults=100).execute()
reviews_list = reviews_page["reviews"]

infinite_loop_canary = 100
while "tokenPagination" in reviews_page:
    reviews_page = reviews_resource.list(packageName=package_name,maxResults=100).execute()
    token=reviews_page["tokenPagination"]["nextPageToken"],
    maxResults=100).execute()
    reviews_list.extend(reviews_page["reviews"])
    infinite_loop_canary -= 1
    if infinite_loop_canary < 0:
        break

脚本中的行 - reviews_resource.list(packageName=package_name,maxResults=100).execute()- 抛出“调用者没有权限”

我不确定需要做什么。任何帮助表示赞赏。

【问题讨论】:

    标签: python android automation google-play-services google-reviews


    【解决方案1】:

    我在这里发布答案,因为我花了很长时间才弄清楚这一点,也许它会帮助其他人。

    你之前需要什么:

    1. 来自https://console.developers.google.com的服务帐号

    2. SA 的私钥。 (使用 .p12 文件)

    3. 在 Play 管理中心,我们需要从开发者帐户授予对此 SA 的访问权限 -> API 访问权限。

    4. 一旦我们点击授予访问权限(从第 3 步开始),我们就会出现权限对话框 - 为所需的应用启用“回复评论”。

       from apiclient.discovery import build
       import httplib2
       from oauth2client import client
       from oauth2client.service_account import ServiceAccountCredentials
      
       SERVICE_ACCOUNT_EMAIL = ('associated_service_email_address_goes_here')
      
       #this is the private key file
       key = 'xxx.p12' 
       scope='https://www.googleapis.com/auth/androidpublisher'
      
       credentials= ServiceAccountCredentials.from_p12_keyfile(SERVICE_ACCOUNT_EMAIL,
       key,
       scopes=[scope])
      
       package_name = "xtestx"
      
       try:
           http = httplib2.Http()
           http = credentials.authorize(http)
           service = build('androidpublisher', 'v3', http=http)
      
           reviews_resource = service.reviews()
           print(reviews_resource)
           reviews_page = reviews_resource.list(packageName=package_name,maxResults=100).execute()
           reviews_list = reviews_page["reviews"]
       except Exception as e:
           ...
      

    权限造成了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-03
      • 1970-01-01
      • 2015-02-27
      • 2021-07-20
      • 2016-01-09
      • 1970-01-01
      • 2018-08-10
      相关资源
      最近更新 更多