PokeGOAPI-Java icon indicating copy to clipboard operation
PokeGOAPI-Java copied to clipboard

Discussion: Any best practice to avoid captcha challenges?

Open clangdev opened this issue 9 years ago • 32 comments

Description: I would like to know how to avoid captcha challenges. I think my "bot" is currently in a state where it's loop is stable enough, until a challenge is to be solved. When playing on my main account (legacy Pokemon GO Android app) I never encountered any captcha challenge.

Steps to reproduce: Just let the bot bot for some time. Very unspecific.

Expected behavior: No captcha challenge to be solved.

Actual behavior: After some time, a captcha challenge is to be solved.

Stacktrace (If it's a crash): no crash

Version: PokeGOAPI-library-all-0.4.1.jar (Development branch)

clangdev avatar Dec 23 '16 17:12 clangdev

How do you know you've gotten a captcha challenge? I only see them once I kill my bot and log in to the real client.

scprotz avatar Dec 24 '16 20:12 scprotz

Maybe I discovered something. I basically use sample TravelToPokestopExample.java to travel anywhere. I think I got captchas twice as often after I changed walk speed from 10.0 to 4.45 km/h. Maybe captcha challenges relate to amount of queries to niantic servers.. I know that changing speed has nothing to do with amount of request/time, but the "hops" my account is doing on the world map changes. At 10 km/h it is 5,555555555555556m (with 2sec sleep in the update location loop) At 4.45 km/h it is 2,472222222222222m (with 2sec sleep in the update location loop)

Does anyone know how often the original client does location updates (what interval)?

PS: Setting Thread.sleep to 3 sec helped a lot. Got no captcha challange for more than an hour, before at 2sec sleep I got it every 10 minutes.

clangdev avatar Dec 26 '16 07:12 clangdev

Requests are not set every time the location updates. I think the main problem here would be the map not being updated at a regular interval, the example only updates it once. In #830, a heartbeat is added, which will make the API update the map and hopefully reduce the amount of captchas received.

Gegy avatar Dec 26 '16 09:12 Gegy

I update my map every 10 sec with an outside thread. If not is busy it waits for it to be set as unbusy and then continue updating. When catching a pokemon a map should not be update.(see how the real app do)

Anyway, is still receive captcha every 30 min (Sometimes more frequent)

RebliNk17 avatar Dec 26 '16 10:12 RebliNk17

With following code I usually get a captcha challenge when looting pokestops, but seldom while walking:

		PokemonGo api=new PokemonGo(new OkHttpClient()); //You need to login properly
		Point source=api.getPoint(); // walking from 
		Point destination=new Point(50.0, 6.0); // walking to
		double speed=4.45; // with 4.45 km/h
		Path path = new Path(source, destination, speed);
		path.start(api);
		try {
			while (!path.isComplete()) {
				// Calculate the desired intermediate point for the
				// current
				// time
				Point nextWayPoint = path.calculateIntermediate(api);
				// Set the API location to that point
				api.setLatitude(nextWayPoint.getLatitude());
				api.setLongitude(nextWayPoint.getLongitude());
				// Sleep for 3 seconds before setting the location again
				Thread.sleep(3000);
			}
		} catch (InterruptedException e) {
		// Stop walking instead of spamming new location updates
		}

clangdev avatar Dec 26 '16 12:12 clangdev

i got a much larger code, which walking+ catches pokemons/looting/sniping/auto incubate/auto drop/auto evolve/transfer ect... catpcha once in 15-30 min.

while just walking + sniping captcha once in 30-60 min...

maybe the pokemon catching or pokestop looting are incorrect somehow.

don't know if 0.45 related or something else...

RebliNk17 avatar Dec 26 '16 13:12 RebliNk17

@RebliNk17 : I just simplified the code I use to just walking from src to dst.

A bot is just useless if you have to sit in front of it checking if there is a captcha challenge to be solved manually. And as I know that I get no captchas while playing with official client app, there must be a something we can make better when using PokeGOAPI.

clangdev avatar Dec 26 '16 13:12 clangdev

I know. I've implemented 2catpcha api to solve my captcha. HatchingEgg said that the amount of captcha in updated api is much lower than using outdated one. Maybe it is the case here...

RebliNk17 avatar Dec 26 '16 13:12 RebliNk17

Does anyone have a more complete example that doesn't cause a Captcha?
Maybe the best way to model is see what a 'real' player does and mimic the timings.

Any suggestions on how to watch the traffic flowing across from the live client to view the messages/timing?

scprotz avatar Dec 26 '16 21:12 scprotz

I want to MITM but need to unroot my phone first ill update you if i'll have any update

BTW, my best run was 35 min without captcha (with: walking+looting+catching pokemons+sniping+auto drop items+auto incubate eggs)...

RebliNk17 avatar Dec 27 '16 00:12 RebliNk17

Using 0.51 API drastically reduces captchas, so far, after running a test bot for a few hours, It has not received a captcha.

Gegy avatar Dec 29 '16 04:12 Gegy

I am still able to trigger a challenge after about 10 minutes, scanning a point for pokemon, now using commit https://github.com/Grover-c13/PokeGOAPI-Java/commit/6be359442786b628a2e177d392ea7129baaec9dd . @gegy1000: Would you like to share some best practice with us?

For moving my player I am basically using the example-code, creating a path from src to dst and plotting the intermediate waypoints with constant speed to the api (very much like in the snippet shown I posted earlier). Is there any better method?

clangdev avatar Dec 29 '16 07:12 clangdev

@gegy1000 I too would like to see some best practices or example code. I don't use path, but rather a custom Haversine distance calculator (which ultimately may be the same thing as in 'path') and update my position every 5-10 seconds. I still also get Captchas regularly.

I actually set up an IPad, connected to a Mac to view the network traffic between the PoGo native app on IOS and server, but because Protobuf is hard to 'read' in TCP traffic, having a hard time understanding it. I am wanting to see what a real conversation from the app to server looks like so I can emulate it as much as possible (and hopefully avoid Captchas).

scprotz avatar Dec 29 '16 07:12 scprotz

@clangdev @scprotz Probably the biggest improvement you will see, is from using the 0.51 hash. Although it is a paid service, you could see a 100% drop in captchas, depending on how human-like your program behaves. With the 0.45 local hash, you will always get captchas, and the amount you can reduce that, without 0.51, is limited.

It's good to add delays between things like evolving, throwing pokeballs, etc, as a human can't do them all right after each other, and some animations take time to complete. It is also best if you don't sent any invalid requests, many actions are checked on the client before a message is sent to the server, such as checking if you have pokeballs in your inventory before throwing one. (although in this case, the API should do that check)

It doesn't matter when you call setLocation, setting the location itself doesn't send a message, just causes that location to be sent with the next request.

Lastly, as scprotz mentioned, if the messages sent closely match the official app, captchas will be reduced.

Gegy avatar Dec 29 '16 09:12 Gegy

@gegy1000 Does this mean the days of the free PokeGOAPI-Java API are numbered? If Niantic force updates everyone to 0.51 or higher, then based on my current understanding, without the correct hash, the current API will stop working. (Maybe I don't understand how the hash affects the API yet well enough) - I'm also assuming that Niantic discontinues support for old hashes.

scprotz avatar Dec 29 '16 09:12 scprotz

With HashKey anything is working like a charm without captchas. Too bad, it is not free. But maybe this is good for the dev environment, that not anyone can spam the niantic-servers with requests.

clangdev avatar Dec 29 '16 11:12 clangdev

@scprotz Yes, the days of this API working as a free service are numbered, as for everyone else. All Pokemon GO apps that connect to the Pokemon GO servers and act as a player will have costs attached, if they are to run with the latest hash. If the latest hash is ever publicized, the API can support it, but for now the only option is buying a hash key.

Gegy avatar Dec 29 '16 13:12 Gegy

@gegy1000 so to be clear, the hash is just the mechanism used to encode protobuf queries to the servers? Isn't that something that can be fairly easily extracted from a decrypted APK or is the hash something more nefarious?

scprotz avatar Dec 29 '16 14:12 scprotz

@scprotz No, finding the hash is a much more complicated task. My knowledge on RE is very limited, but the hash function has to be found, and then reverse-engineered in compiled and obfuscated C bytecode.

Gegy avatar Dec 29 '16 14:12 Gegy

Let's summarize: Best practice is to mimic original client as close as possible, to avoid captchas. To get even closer to the original client it is necessary to buy v0.51.0 Hashcode. This highly reduces captcha challenges. I got none today, "bot" working (watching a fixed location for pokemon spawns) for 12hours without any captcha. As this is for now a reasonable conclusion I will close this discussion for now. Maybe we will get back to this topic with future API versions.

clangdev avatar Dec 29 '16 19:12 clangdev