首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android-market检索空结果

android-market检索空结果
EN

Stack Overflow用户
提问于 2013-03-02 23:34:39
回答 1查看 667关注 0票数 1

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

Google play市场。

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

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

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

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

代码语言:javascript
复制
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();吗?

因此,我的所有查询都返回空集合,

尽管我看到有一些名字作为输入。

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

EN

回答 1

Stack Overflow用户

发布于 2013-03-03 04:20:17

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

代码语言:javascript
复制
  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();
    }

如果你还想下载截图或图片,你应该调用这个查询:

代码语言:javascript
复制
    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 <------------");
}
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15176193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档