2013-03-02 38 views
1

我想收获一些特定应用程序的数据android-market检索空的结果

Google play marketplace。

我已经使用这个非官方的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();在这一点上?

我所有的quesries空车返回集合作为一个结果,

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

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

+0

这种方式是不是有效 如果你有你的AppId应该使用该查询。它不是官方API,开发人员可以多次更改或更新,因此您需要多次更改代码或方法。我用这个非官方的API创建了一个应用程序,第一次运行良好,然后在1个月后崩溃,并再次开始工作,然后再次崩溃。此API可以检索关于市场上所有应用程序的信息。我认为开发人员拥有自己的数据库,并在需要时进行更新。我决定不使用这个API。 – Daryn 2013-11-22 09:42:30

回答

0

session.flush()关闭你的会话 你应该打开每个查询的会话。请注意,用户可以锁定几分钟,因此您应该有许多用户访问这些查询。如果你也想下载screenshoot或图像,你应该把这个查询

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 <------------"); 
} 
}); 
+0

'session.flush()关闭你的会话“,那我该如何正确使用它?我不知道何时会执行回调...... – 2013-03-02 21:49:07

+0

您可以尝试同时打开与同一用户的多个会话(我不尝试)。或者您可以使用几个不同的帐户来打开不同的会话。 – Beno 2013-03-02 23:22:28

+0

这是不实际的。如果我想获取100个应用程序 - 我必须使用100个帐户? – 2013-03-03 11:46:05