use of okhttp3.Credentials in project PokeGOAPI-Java by Grover-c13.
the class TransferOnePidgeyExample method main.
/**
* Transfers one pidgey from the player's inventory.
*/
public static void main(String[] args) {
OkHttpClient http = new OkHttpClient();
PokemonGo api = new PokemonGo(http);
try {
HashProvider hasher = ExampleConstants.getHashProvider();
api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
List<Pokemon> pidgeys = api.inventories.pokebank.getPokemonByPokemonId(PokemonIdOuterClass.PokemonId.PIDGEY);
if (pidgeys.size() > 0) {
Pokemon pest = pidgeys.get(0);
// print the pokemon data
pest.debug();
ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result result = pest.transferPokemon();
Log.i("Main", "Transfered Pidgey result:" + result);
} else {
Log.i("Main", "You have no pidgeys :O");
}
} catch (RequestFailedException e) {
// failed to login, invalid credentials, auth issue or server issue.
Log.e("Main", "Failed to login. Invalid credentials, captcha or server issue: ", e);
}
}
use of okhttp3.Credentials in project PokeGOAPI-Java by Grover-c13.
the class UseIncenseExample method main.
/**
* Catches a pokemon at an area.
*/
public static void main(String[] args) {
OkHttpClient http = new OkHttpClient();
PokemonGo api = new PokemonGo(http, new SystemTimeImpl());
try {
HashProvider hasher = ExampleConstants.getHashProvider();
api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
api.inventories.itemBag.useIncense();
} catch (RequestFailedException e) {
// failed to login, invalid credentials, auth issue or server issue.
Log.e("Main", "Failed to login, captcha or server issue: ", e);
}
}
use of okhttp3.Credentials in project PokeGOAPI-Java by Grover-c13.
the class CheckEvolutionExample method main.
/**
* Displays pokemon evolutions
*
* @param args Not used
*/
public static void main(String[] args) {
OkHttpClient http = new OkHttpClient();
final PokemonGo api = new PokemonGo(http);
try {
// Login and set location
HashProvider hasher = ExampleConstants.getHashProvider();
api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
// Get the evolution meta from the item templates received from the game server
Evolutions evolutionMeta = api.itemTemplates.evolutions;
System.out.println("Evolutions: ");
for (PokemonId pokemon : PokemonId.values()) {
List<PokemonId> evolutions = evolutionMeta.getEvolutions(pokemon);
if (evolutions.size() > 0) {
System.out.println(pokemon + " -> " + evolutions);
}
}
System.out.println();
System.out.println("Most basic: ");
for (PokemonId pokemon : PokemonId.values()) {
List<PokemonId> basic = evolutionMeta.getBasic(pokemon);
if (basic.size() > 0) {
// Check this is not the most basic pokemon
if (!(basic.size() == 1 && basic.contains(pokemon))) {
System.out.println(pokemon + " -> " + basic);
}
}
}
System.out.println();
System.out.println("Highest: ");
for (PokemonId pokemon : PokemonId.values()) {
List<PokemonId> highest = evolutionMeta.getHighest(pokemon);
if (highest.size() > 0) {
// Check this is not the highest pokemon
if (!(highest.size() == 1 && highest.contains(pokemon))) {
System.out.println(pokemon + " -> " + highest);
}
}
}
} catch (RequestFailedException e) {
// failed to login, invalid credentials, auth issue or server issue.
Log.e("Main", "Failed to login, captcha or server issue: ", e);
}
}
use of okhttp3.Credentials in project PokeGOAPI-Java by Grover-c13.
the class TransferMultiplePokemon method main.
/**
* Transfers all bad pokemon from the player's inventory.
*/
public static void main(String[] args) {
OkHttpClient http = new OkHttpClient();
PokemonGo api = new PokemonGo(http);
try {
HashProvider hasher = ExampleConstants.getHashProvider();
api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
PokeBank pokebank = api.inventories.pokebank;
List<Pokemon> pokemons = pokebank.pokemons;
List<Pokemon> transferPokemons = new ArrayList<>();
// Find all pokemon of bad types or with IV less than 25%
for (Pokemon pokemon : pokemons) {
PokemonId id = pokemon.getPokemonId();
double iv = pokemon.getIvInPercentage();
if (iv < 90) {
if (id == PokemonId.RATTATA || id == PokemonId.PIDGEY || id == PokemonId.CATERPIE || id == PokemonId.WEEDLE || id == PokemonId.MAGIKARP || id == PokemonId.ZUBAT || iv < 25) {
transferPokemons.add(pokemon);
}
}
}
System.out.println("Releasing " + transferPokemons.size() + " pokemon.");
Pokemon[] transferArray = transferPokemons.toArray(new Pokemon[transferPokemons.size()]);
Map<PokemonFamilyId, Integer> responses = pokebank.releasePokemon(transferArray);
// Loop through all responses and find the total amount of candies earned for each family
Map<PokemonFamilyId, Integer> candies = new HashMap<>();
for (Map.Entry<PokemonFamilyId, Integer> entry : responses.entrySet()) {
int candyAwarded = entry.getValue();
PokemonFamilyId family = entry.getKey();
Integer candy = candies.get(family);
if (candy == null) {
// candies map does not yet contain the amount if null, so set it to 0
candy = 0;
}
// Add the awarded candies from this request
candy += candyAwarded;
candies.put(family, candy);
}
for (Map.Entry<PokemonFamilyId, Integer> entry : candies.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue() + " candies awarded");
}
} catch (RequestFailedException e) {
// failed to login, invalid credentials, auth issue or server issue.
Log.e("Main", "Failed to login. Invalid credentials, captcha or server issue: ", e);
}
}
use of okhttp3.Credentials in project PokeGOAPI-Java by Grover-c13.
the class GoogleCredentialProvider method login.
/**
* Starts a login flow for google using googles device oauth endpoint.
*
* @throws LoginFailedException if an exception occurs while attempting to log in
* @throws InvalidCredentialsException if invalid credentials are used
*/
public void login() throws LoginFailedException, InvalidCredentialsException {
HttpUrl url = HttpUrl.parse(OAUTH_ENDPOINT).newBuilder().addQueryParameter("client_id", CLIENT_ID).addQueryParameter("scope", "openid email https://www.googleapis.com/auth/userinfo.email").build();
// Create empty body
RequestBody reqBody = RequestBody.create(null, new byte[0]);
Request request = new Request.Builder().url(url).method("POST", reqBody).build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (IOException e) {
throw new LoginFailedException("Network Request failed to fetch tokenId", e);
}
Moshi moshi = new Moshi.Builder().build();
GoogleAuthJson googleAuth = null;
try {
googleAuth = moshi.adapter(GoogleAuthJson.class).fromJson(response.body().string());
Log.d(TAG, "" + googleAuth.expiresIn);
} catch (IOException e) {
throw new LoginFailedException("Failed to unmarshell the Json response to fetch tokenId", e);
}
Log.d(TAG, "Get user to go to:" + googleAuth.verificationUrl + " and enter code:" + googleAuth.userCode);
onGoogleLoginOAuthCompleteListener.onInitialOAuthComplete(googleAuth);
GoogleAuthTokenJson googleAuthTokenJson;
try {
while ((googleAuthTokenJson = poll(googleAuth)) == null) {
Thread.sleep(googleAuth.interval * 1000);
}
} catch (InterruptedException e) {
throw new LoginFailedException("Sleeping was interrupted", e);
} catch (IOException e) {
throw new LoginFailedException(e);
} catch (URISyntaxException e) {
throw new LoginFailedException(e);
}
Log.d(TAG, "Got token: " + googleAuthTokenJson.idToken);
onGoogleLoginOAuthCompleteListener.onTokenIdReceived(googleAuthTokenJson);
expiresTimestamp = System.currentTimeMillis() + (googleAuthTokenJson.expiresIn * 1000 - REFRESH_TOKEN_BUFFER_TIME);
tokenId = googleAuthTokenJson.idToken;
refreshToken = googleAuthTokenJson.refreshToken;
}
Aggregations