1

我想收集一些关于特定应用程序的数据

谷歌游戏市场。

我使用了这个非官方的 API:

https://code.google.com/p/android-market-api/

这是我的代码,它基本上获取应用程序名称列表

并尝试在每个应用程序上获取其他数据:

public void printAllAppsData(ArrayList<AppHarvestedData> dataWithAppsNamesOnly)
{       
    MarketSession session = new MarketSession();
    session.login("[myGamil]","[myPassword]");
    session.getContext().setAndroidId("dead00beef");

    final ArrayList<AppHarvestedData> finalResults = new ArrayList<AppHarvestedData>();

    for (AppHarvestedData r : dataWithAppsNamesOnly)
    {
    String query = r.name;
    AppsRequest appsRequest = AppsRequest.newBuilder()
                                    .setQuery(query)
                                    .setStartIndex(0).setEntriesCount(10)
                                    //.setCategoryId("SOCIAL") 
                                    .setWithExtendedInfo(true)
                                    .build();

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

                      List<App> apps = response.getAppList(); 
                        for (App app : apps) { 
                                AppHarvestedData r = new AppHarvestedData(); 

                                r.title = app.getTitle();
                                r.description = app.getExtendedInfo().getDescription();
                                String tmp = app.getExtendedInfo().getDownloadsCountText();
                                tmp = tmp.replace('<',' ').replace('>',' ');
                                int indexOf = tmp.indexOf("-");
                                tmp = (indexOf == -1) ? tmp : tmp.substring(0, indexOf);
                                r.downloads = tmp.trim();
                                r.rating = app.getRating();
                                r.version = app.getVersion(); 
                                r.userRatingCount = String.valueOf(app.getRatingsCount()); 
                                finalResults.add(r);
                                }
                        }
             });
    session.flush();
    }

    for(AppHarvestedData res : finalResults)
    {           
            System.out.println(res.toString());
    }
}

}

我现在应该打电话session.flush();吗?

结果,我所有的查询都返回空集合,

即使我看到有一些名称作为输入。

当我只发送一个硬编码的应用程序名称作为查询时,它工作正常。

4

1 回答 1

0

session.flush() 关闭你的会话你应该为每个查询打开会话。注意用户可能会被锁定几分钟,所以你应该有很多用户来处理这些查询。如果您有 AppId,您应该使用该查询:

  String query = r.name;
    AppsRequest appsRequest = AppsRequest.newBuilder()
                                    .setAppId("com.example.android")               
                                    .setWithExtendedInfo(true)
                                    .build();

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

                      List<App> apps = response.getAppList(); 
                        for (App app : apps) { 
                                AppHarvestedData r = new AppHarvestedData(); 

                                r.title = app.getTitle();
                                r.description = app.getExtendedInfo().getDescription();
                                String tmp = app.getExtendedInfo().getDownloadsCountText();
                                tmp = tmp.replace('<',' ').replace('>',' ');
                                int indexOf = tmp.indexOf("-");
                                tmp = (indexOf == -1) ? tmp : tmp.substring(0, indexOf);
                                r.downloads = tmp.trim();
                                r.rating = app.getRating();
                                r.version = app.getVersion(); 
                                r.userRatingCount = String.valueOf(app.getRatingsCount()); 
                                finalResults.add(r);
                                }
                        }
             });
    session.flush();
    }

如果您还想下载屏幕截图或图像,则应调用此查询:

    GetImageRequest? imgReq; imgReq = GetImageRequest?.newBuilder().setAppId(appId).setImageUsage(AppImageUsage?.SCREENSHOT).setImageId("0").build();

session.append(imgReq, new Callback<GetImageResponse>() {
@Override public void onResult(ResponseContext? context, GetImageResponse? response) {
Log.d(tag, "------------------> Images response <----------------"); if(response != null) {
try {
//imageDownloader.download(image, holder.image, holder.imageLoader);
Log.d(tag, "Finished downloading screenshot 1...");
} catch(Exception ex) {
ex.printStackTrace();
}
} else {
Log.e(tag, "Response was null");
} Log.d(tag, "------------> End of Images response <------------");
}
});
于 2013-03-02T20:20:16.627 回答