如何通过Android中的包名从Play商店获取应用类别?

时间:2015-02-04 12:31:49

标签: 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();

3 个答案:

答案 0 :(得分:3)

使用此脚本:

######## 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)

答案 1 :(得分:2)

这就是我所做的,最好和最简单的解决方案

https://androidquery.appspot.com/api/market?app=your.unique.package.name  

或者你可以获得源html并从中获取字符串...

https://play.google.com/store/apps/details?id=your.unique.package.name  

从中获取此字符串 - 使用split或substring方法

<span itemprop="genre">Sports</span>  

在这种情况下,运动是您的类别

答案 2 :(得分:0)

使用android-market-api它将提供应用程序的所有信息