如何登录“ https://github.com/NoMore201/googleplay-api”

时间:2018-08-09 06:06:52

标签: python api documentation

由于我无法通过文档了解内容,因此如果要使用test.py作为示例,请提供输入电子邮件ID和密码的帮助。

from gpapi.googleplay import GooglePlayAPI, RequestError
import sys
import argparse

ap = argparse.ArgumentParser(description='Test download of expansion files')
ap.add_argument('-e', '--email', dest='email', help='google username')
ap.add_argument('-p', '--password', dest='password', help='google password')

args = ap.parse_args()

server = GooglePlayAPI('it_IT', 'Europe/Rome')

# LOGIN
print('\nLogging in with email and password\n')
server.login(args.email, args.password, None, None)
gsfId = server.gsfId
authSubToken = server.authSubToken
print('\nNow trying secondary login with ac2dm token and gsfId saved\n')
server = GooglePlayAPI('it_IT', 'Europe/Rome')
server.login(None, None, gsfId, authSubToken)

# SEARCH

apps = server.search('telegram', 34, None)

print('\nSearch suggestion for "fir"\n')
print(server.searchSuggest('fir'))

print('nb_result: 34')
print('number of results: %d' % len(apps))

print('\nFound those apps:\n')
for a in apps:
    print(a['docId'])

1 个答案:

答案 0 :(得分:1)

我重新编写了一部分代码,对其进行了现代化(Python 3.7),并使用了全局变量而不是系统参数(命令行)。我评论说最好,我可以使用给定的GitHub页面和源代码。

from gpapi.googleplay import GooglePlayAPI

# Create global variables for easy settings change and use.
LOCALE = "us_US"
TIMEZONE = "America/Chicago"
MAX_RESPONSE = 34
APP_NAME = "Super Fun Game"
EMAIL = "test@gmail.com"
PASSWORD = "stackoverflow5"

# Create instance of API with ( locale, time zone )
server = GooglePlayAPI(locale = LOCALE, timezone = TIMEZONE)

# Login using just username and password.
print("\nTrying log in with just email and password\n")
server.login(email = "abc123babyYouandMe@gmail.com", password = "jaksun5")
gsfId = server.gsfId
authSubToken = server.authSubToken

# Now that we've been authorized once, we can use the gsfID and token previously
# generated to create a new instance w/o email or password.
print("\nTrying secondary login with ac2dm token and gsfId saved...\n")
server = GooglePlayAPI(locale = LOCALE, timezone = TIMEZONE)
server.login(gsfId = gsfId, authSubToken = authSubToken)

# Search the Play Store using `search` function
# First: Search query for the Play Store.
# Specify the maximum amount of apps that meet criteria that can be returned.
# Third param is `offset`. Determines if you want to start at a certain
# index in the returned list. Default is `None`.
apps = server.search(query = APP_NAME, nb_result = MAX_RESPONSE)

# Get the suggested search options from our desired app name
print("Search Suggestions for `%s`:" % APP_NAME)
print(server.searchSuggest(APP_NAME))

# Print our max limit and then the actual amount returned
print("Max #of Results: %i" % MAX_RESPONSE)
print("Actual #of Results: %d" % len(apps))

# if at least 1 app found, then print out its ID.
if len(apps) > 0:
    print("Found apps: ")
    # each app acts as a Dictionary
    for _app in apps:
        print("App[docID]: %s" % app["docId"])

PS:坚持使用PEP 8来编码样式,约定,命名等。由于您刚开始,它对于编码自己的程序 和理解其他程序非常有用。 。

资源