java - 如何通过 Android 中的包名从 Play 商店获取 App 类别?

标签 java android

我想通过其唯一标识符(即包名称)从 Play 商店获取应用类别,我使用以下代码但不返回任何数据。我也尝试使用此 AppsRequest.newBuilder().setAppId(query) 仍然没有帮助。 谢谢。

                String AndroidId = "dead000beef";
                MarketSession session = new MarketSession();
                session.login("email", "passwd");
                session.getContext().setAndroidId(AndroidId);

                String query = "package:com.king.candycrushsaga";
                AppsRequest appsRequest = AppsRequest.newBuilder().setQuery(query).setStartIndex(0)
                        .setEntriesCount(10).setWithExtendedInfo(true).build();

                session.append(appsRequest, new Callback<AppsResponse>() {
                    @Override
                    public void onResult(ResponseContext context, AppsResponse response) {

                        String response1 = response.toString();
                        Log.e("reponse", response1);

                    }
                });
                session.flush();

最佳答案

使用这个脚本:

######## Fetch App names and genre of apps from playstore url, using pakage names ############# 
"""
Reuirements for running this script:
1. requests library
Note: Run this command to avoid insecureplatform warning pip install --upgrade ndg-httpsclient
2. bs4

pip install requests
pip install bs4
"""

import requests
import csv
from bs4 import BeautifulSoup

# url to be used for package
APP_LINK = "https://play.google.com/store/apps/details?id="
output_list = []; input_list = []

# get input file path
print "Need input CSV file (absolute) path \nEnsure csv is of format: <package_name>, <id>\n\nEnter Path:"
input_file_path = str(raw_input())

# store package names and ids in list of tuples
with open(input_file_path, 'rb') as csvfile:
    for line in csvfile.readlines():
        (p, i) = line.strip().split(',')
        input_list.append((p, i))


print "\n\nSit back and relax, this might take a while!\n\n"

for package in input_list:

    # generate url, get html
    url = APP_LINK + package[0]
    r = requests.get(url)

    if not (r.status_code==404):
        data = r.text
        soup = BeautifulSoup(data, 'html.parser')

        # parse result
        x = ""; y = "";
        try:
            x = soup.find('div', {'class': 'id-app-title'})
            x = x.text
        except:
            print "Package name not found for: %s" %package[0]

        try:
            y = soup.find('span', {'itemprop': 'genre'})
            y = y.text
        except:
            print "ID not found for: %s" %package[0]

        output_list.append([x,y])

    else:
        print "App not found: %s" %package[0]

# write to csv file
with open('results.csv', 'w') as fp:
    a = csv.writer(fp, delimiter=",")
    a.writerows(output_list)

关于java - 如何通过 Android 中的包名从 Play 商店获取 App 类别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28321493/

相关文章:

java - CoreData 和 Hibernate 的区别

java - Java 小程序的替代品

java.sql.SQLDataException : An attempt was made to get a data value of type 'BOOLEAN' from type 'DATE' 异常

java - 加载数据时显示 ProgressDialog 并返回 View

java - 删除哈希表元素不释放内存

java - 使用 FXML 中的数据绑定(bind)表达式填充 tableView 中的项目?

java - 如何以编程方式从 Android 应用程序生成 apk 文件?

android - 在 MPAndroidChart 中显示单个 x 的多个 y 值

Android Studio 烦人的 layout_width 和 layout_height 弹出窗口

android - 涟漪效应有一个小的延迟,使其不可见