Akdeniz / google-play-crawler

Play with Google Play API :)
Other
561 stars 204 forks source link

Please reduce your request rate #85

Open hoseinmobasher opened 8 years ago

hoseinmobasher commented 8 years ago

Hello, I have an issue on crawling apps. After some tests, Google says "Please reduce your request rate" and return 429 status code. How should I do? Could you please guide me to solve my problem?

Exception in thread "main" com.akdeniz.googleplaycrawler.GooglePlayException:

429 Too Many Requests

Please reduce your request rate.

at com.akdeniz.googleplaycrawler.GooglePlayAPI.executeHttpRequest(GooglePlayAPI.java:526)
at com.akdeniz.googleplaycrawler.GooglePlayAPI.executeGet(GooglePlayAPI.java:515)
at com.akdeniz.googleplaycrawler.GooglePlayAPI.executeGETRequest(GooglePlayAPI.java:419)
at com.akdeniz.googleplaycrawler.GooglePlayAPI.list(GooglePlayAPI.java:303)
at hossein.GooglePlayCrawler.main(GooglePlayCrawler.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

The snippet I used is:

    GooglePlayAPI api = new GooglePlayAPI("username@gmail.com", "password", "android-id");
    api.setClient(new DefaultHttpClient(GooglePlayAPI.getConnectionManager()));
    api.login();

    FileWriter appWriter = new FileWriter(new File("/Users/hossein/Desktop/Dataset/GP", "apps.txt"));
    FileWriter revWriter = new FileWriter(new File("/Users/hossein/Desktop/Dataset/GP", "reviews.txt"));

    for (int appIndex = 0; appIndex < 5000; appIndex += 100) {
        ListResponse listResponse = api.list("SPORTS", "apps_topselling_free", appIndex, 100);
        List<DocV2> apps = listResponse.getDoc(0).getChildList();

        for (DocV2 app : apps) {
            AppDetails appDetail = app.getDetails().getAppDetails();
            appWriter.write(String.format("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%d\n",
                    appDetail.getPackageName(), appDetail.getTitle(), appDetail.getAppType(), appDetail.getDeveloperName(),
                    appDetail.getNumDownloads(), appDetail.getVersionString(), appDetail.getUploadDate(), appDetail.getContentRating()));
            System.out.println("Processing: " + appDetail.getPackageName());
            for (int reviewIndex = 0; reviewIndex < 500; reviewIndex += 20) {
                ReviewResponse review = api.reviews(appDetail.getPackageName(), GooglePlayAPI.REVIEW_SORT.HELPFUL, reviewIndex, 20);
                List<Review> reviews = review.getGetResponse().getReviewList();

                for (Review r : reviews) {
                    revWriter.write(String.format("%s\t%s\t%s\t%s\t%s\t%d\t%d\t%s\n",
                            appDetail.getPackageName(), r.getAuthorName(), r.getTitle(), r.getComment(),
                            r.getDeviceName(), r.getStarRating(), r.getTimestampMsec(), r.getUrl()));
                }
            }
        }
    }

    appWriter.close();
    revWriter.close();
WadeaHijjawi commented 6 years ago

I have the same error, any solution for this problem?

Fuzion24 commented 6 years ago

You could either slow the requests down or use multiple accounts.