nicklaswallgren / pokemongoapi-php Goto Github PK
View Code? Open in Web Editor NEWPokemon Go API PHP library
License: BSD 2-Clause "Simplified" License
Pokemon Go API PHP library
License: BSD 2-Clause "Simplified" License
In Pokedex.php we have this method
public function get($pokemonId)
{
return $this->items[$pokemonId];
}
If I set a param, for example 150 (nobody has Mewtwo), I receive an error.
I suggest to modify then in this way
public function get($pokemonId)
{
return isset($this->items[$pokemonId]) ? $this->items[$pokemonId] : null;
}
So, if I want to che every Pokemon, from 1 to 151 in my project page, I will write:
for($i=1; $i<= 151; $i++)
{
if($pokedex->get($i) !== null)
{
$pokemon = $pokedex->get($i);
$entountered = $pokemon->getTimesEncountered();
$captured = $pokemon->getTimesCaptured();
}
else
{
$entountered = 0;
$captured = 0;
}
}
Else, every time I will pass $i and it's not in the items array, I get an error
For now we only support PHP on 64bit platform
What should I do?
Is there a method showing if pokemon can be evolved ?
Cannot find it :(
Im making simple web to show whole inventory and pokemons, i want to display candies for pokemons that can be evolved.
You could consider the idea to extend the method to obtain the pokemons in your inventory, by adding a parameter "sortby", with # pokedex, name, CP, level and IV (if you can calculate and store the Individual Value of each pokemon)
i am new in class php
The response
NicklasW\PkmGoApi\Api\Player\Data\Profile\Currencies Object
(
[currencies:protected] => Array
(
[0] => NicklasW\PkmGoApi\Api\Player\Data\Profile\Currency Object
(
[name:protected] => POKECOIN
[amount:protected] => 0
)
[1] => NicklasW\PkmGoApi\Api\Player\Data\Profile\Currency Object
(
[name:protected] => STARDUST
[amount:protected] => 17100
)
)
)
I want to print it like this => You have x stardust and x POKECOIN
but i cant find a way as i am new to class php
as in #19 i tried uasort() method but i get a Warning: uasort() expects parameter 1 to be array
whenever i tried to convert it to array it won't convert.
Can you please help me with this ?
$currency = $profileData->getCurrencies();
uasort($currency, function (\NicklasW\PkmGoApi\Api\Player\Data\Profile\Currencies $c) {
return $c->getState();
});
Hello again !
I didn't found how can I get the type of pokemon, like water, poison, fire etc...
I tried getPokemonFamilyId but it is return the pokemon id.
If someone can help me !
PS: I really like this API ! Thank you very much !
$pokeBank = $inventory->getItems()->getPokeBank();
// print_r($pokeBank);
$pokemon = $pokeBank->getPokemonsByType(PokemonId::RATTATA);
print_r($pokemon);
Prints that i have 2 Rattata
So i just want to print the Rattatas Cp
and transfer the lowest one.
How can i do?
Thank you for everything :)
I was having many errors in this script but when i updated my php version to php7 all the errors gone away
sorry for my bad English
Hello ,
Can you tell me how to fix this error
I am using PTC login
When i tried to echo token it shows the correct token
Fatal error: Uncaught exception 'NicklasW\PkmGoApi\Handlers\RequestHandler\Exceptions\AuthenticationException' with message 'Invalid authentication token provided' in C:\xampp\htdocs\poke\src\Handlers\RequestHandler.php:85 Stack trace: #0 C:\xampp\htdocs\poke\src\Handlers\RequestHandler.php(93): NicklasW\PkmGoApi\Handlers\RequestHandler->handle(Object(NicklasW\PkmGoApi\Requests\GetInventoryRequest)) #1 C:\xampp\htdocs\poke\src\Services\Request\InventoryRequestService.php(19): NicklasW\PkmGoApi\Handlers\RequestHandler->handle(Object(NicklasW\PkmGoApi\Requests\GetInventoryRequest)) #2 C:\xampp\htdocs\poke\src\Api\Player\Inventory.php(37): NicklasW\PkmGoApi\Services\Request\InventoryRequestService->getInventory() #3 C:\xampp\htdocs\poke\src\Api\Player\Inventory.php(25): NicklasW\PkmGoApi\Api\Player\Inventory->update() #4 C:\xampp\htdocs\poke\examples\RetrievePlayerStatsExample.php(26): NicklasW\PkmGoApi\Api\Player\Inventory->getItems() #5 C:\xampp\htdocs\PokemonGoPhp\examples\RetrievePlayerStatsExample.php(34): RetrievePlayerStatsEx in C:\xampp\htdocs\PokemonGoPhp\src\Handlers\RequestHandler.php on line 85
When i print token
POGOProtos\Networking\Envelopes\RequestEnvelope_AuthInfo Object ( [_unknown:POGOProtos\Networking\Envelopes\RequestEnvelope_AuthInfo:private] => [provider:POGOProtos\Networking\Envelopes\RequestEnvelope_AuthInfo:private] => ptc [token:POGOProtos\Networking\Envelopes\RequestEnvelope_AuthInfo:private] => POGOProtos\Networking\Envelopes\RequestEnvelope_AuthInfo_JWT Object ( [_unknown:POGOProtos\Networking\Envelopes\RequestEnvelope_AuthInfo_JWT:private] => [contents:POGOProtos\Networking\Envelopes\RequestEnvelope_AuthInfo_JWT:private] => TGT-8200905-GIpxnOlc3dmGbcqBhHgratMaYbMMiDQqUG2cPXV71hc3eCYwtx-sso.pokemon.com [unknown2:POGOProtos\Networking\Envelopes\RequestEnvelope_AuthInfo_JWT:private] => 0 [_unknown:ProtobufMessage:private] => ) [_unknown:ProtobufMessage:private] => )
Hi,
i have this message when i try to run a example class:
"php RetrievePlayerStatsExample.php
For now we only support PHP on 64bit platforms \n"
I work on Windows 10 - 64bit.
Thanks for the API, from France!
Is it possible to get a Pokestop by ID ?
example:
require DIR . '/../vendor/autoload.php';
use NicklasW\PkmGoApi\Authenticators\Factory;
use NicklasW\PkmGoApi\Kernels\ApplicationKernel;
use POGOProtos\Enums\PokemonId;
** what does it mean?
Hello,
not thought about adding logins using OAuth from Google?
Thanks
Is there any place to donate for this project?
Hello, i have upload your api on my website and now, i don't understand how to work this api, i need to create a index.php file .. ?
Please, help. Thanks
Hello i am getting these errors
Warning: require(C:\xampp\htdocs\poke\examples/../vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\poke\examples\RetrievePlayerStatsExample.php on line 3
and
Fatal error: require(): Failed opening required 'C:\xampp\htdocs\poke\examples/../vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\poke\examples\RetrievePlayerStatsExample.php on line 3
My Current PHP version:
5.6.14
thanks
Hello !
How can I retrieve all pokemon one by one ?
for example like this:
foreach($allPokemon => $pokemon){ echo $pokemon->getName(); }
Thank you !
are in the code the attacks and damages of a pokemon?
or can we have only the id of that attack?
the pokemonfamiliy id is missing. so we can't get candy using that value now
Hi, I'm trying to rigure out how to get the current exp level.
We have only these 3 methods:
$Experience = $playerStats->getExperience();
$PrevLevelXp = $playerStats->getPrevLevelXp();
$getNextLevelXp = $playerStats->getNextLevelXp();
In my case, I'm level 28 and I get these values (check the red rectangle)
In game I can see this other 2 info:
Current Exp: 3665
Exp for THIS level: 300000
With
$getNextLevelXp - $Experience
I get te Exp needed to next level, same if I do 300000-3665
Same result: 296335
I'd like to write, like in game 296335/300000, but this "300000" value is not calculated in method in this API, or yes?
There's any way to get this value?
im trying this code on godaddy server and php vision is 5.6
when i trying transfer pokemon and this happened:
Parse error: syntax error, unexpected 'UNSET' (T_UNSET), expecting identifier (T_STRING) in /API/res/POGOProtos/Networking/Responses/ReleasePokemonResponse.php on line 15
Hey,
PokeAdvisor uses this url to get a token:
https://accounts.google.com/o/oauth2/auth?client_id=848232511240-73ri3t7plvk96pj4f85uj8otdat2alem.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=openid%20email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
How can I use this token to obtain the OAuth token ? Can PokemonGoAPI-PHP be tweaked in a way so it uses the token obtained from the above url ?
$pokedex = $inventory->getItems()->getPokedex()->getPokedexItems()
This shoud give me all pokedex info about my pokemon in pokedex (pokedexEntryNumber, timesEncountered, timesCaptured , etc)
But if I print the $pokedex array:
Array ( [0] => NicklasW\PkmGoApi\Api\Player\Data\Inventory\PokedexItem Object ( [pokedexEntryNumber:protected] => 0 [timesEncountered:protected] => 2 [timesCaptured:protected] => 2 [evolutionStonePieces:protected] => 0 [evolutionStones:protected] => 0 ) )
it's empty, no data stored.
Fatal error: Call to a member function getAttribute() on null in /home/user123/public_html/files/PokemonGoAPI-PHP/src/Authenticators/GoogleOauth/Parsers/AuthenticationConfirmationInformationParser.php on line 56
When attempting to use your example
For now, every time refresh or use a new function this will send a request to google get authenticator. I think may be just send once request and use token to get information after.
When I tried to get the $pokemon->getCandies()->getCount() I get few errors with some Pokemon.
Then, I looked deepest in the code and I found out that there's something wrong in the getPokemonFabilyId method.
So, I added few row of code to debug this method and sometimes, it doesn't go recursive. In most of cases yes, but sometimes not.
In the example I attached, in the block 3 it writes "found ID 11" but the family of Caterpie it's 10.
And then I get the error
Invalid pokemon family id provided. Pokemon family id '11' in C:\wamp64\www\PokemonGoAPI-PHP\src\Api\Player\Data\Inventory\CandyBank.php on line 53
because it's true: pokemon family id 11 doesn't exist in PokemonFamilyId.php
Another weird thing is that it not always echo "Looking for ID: xxx", but only echo "Found Family ID: xxx" and maybe these 2 errors are connected each others.
With PTC error:
"
PHP Fatal error: Uncaught exception 'Exception' with message 'write_varint(): Error writing byte' in PokemonGoAPI-PHP/includes/protocolbuffers.inc.php:642
Stack trace:
#0 PokemonGoAPI-PHP/res/POGOProtos/Networking/Envelopes/RequestEnvelope.php(330): Protobuf::write_varint(Resource id #153, 8145806132888207460)
#1 PokemonGoAPI-PHP/includes/protocolbuffers.inc.php(103): POGOProtos\Networking\Envelopes\RequestEnvelope->write(Resource id #153)
#2 PokemonGoAPI-PHP/src/Handlers/RequestHandler.php(160): ProtobufMessage->toProtobuf()
#3 ... in PokemonGoAPI-PHP/includes/protocolbuffers.inc.php on line 642
"
With Google error:
"
PHP Fatal error: Cannot use object of type stdClass as array in PokemonGoAPI-PHP/src/Authenticators/GoogleOauth/Parsers/Results/AuthenticationTokenResult.php on line 46
"
What the problem?
Hey,
It would be great if you could add the option to check either a Lucky egg is set or not.
In "vendor/nicklasw/pogoprotos-php/src/POGOProtos/Networking/Requests/" folder there is a file "RequestType.php"
In the list of all its const, there is a declaration: "const ECHO = 666;" that give me error at runtime.
I checked the previous version and this declaration was "const ECHO_REQUEST = 666;"
So, now, I put it back to ECHO_REQUEST and I don't have the error anymore. But I'm not sure everything will properly work.
Hello, when I try to run examples it happens, it's a LAMP Installation from Digitalocean.
It's running 64-Bit as you can see here http://82.196.5.58/PokemonGoAPI-PHP/
http://82.196.5.58/PokemonGoAPI-PHP/examples/RetrievePlayerStatsExample.php Just gives 500 error.
Any ideas?
Thanks in advance.
i can get anthor users lv ?
I am having some issues
Fatal error: Uncaught exception 'Dotenv\Exception\InvalidPathException' with message 'Unable to read the environment file at C:\xampp\htdocs\poke\src\Kernels/../...env.' in C:\xampp\htdocs\poke\vendor\vlucas\phpdotenv\src\Loader.php:75 Stack trace: #0 C:\xampp\htdocs\poke\vendor\vlucas\phpdotenv\src\Loader.php(52): Dotenv\Loader->ensureFileIsReadable() #1 C:\xampp\htdocs\poke\vendor\vlucas\phpdotenv\src\Dotenv.php(90): Dotenv\Loader->load() #2 C:\xampp\htdocs\poke\vendor\vlucas\phpdotenv\src\Dotenv.php(48): Dotenv\Dotenv->loadData() #3 C:\xampp\htdocs\poke\src\Kernels\Kernel.php(105): Dotenv\Dotenv->load() #4 C:\xampp\htdocs\poke\src\Kernels\Kernel.php(84): NicklasW\PkmGoApi\Kernels\Kernel->loadEnvironmentVariables() #5 C:\xampp\htdocs\poke\src\Kernels\ApplicationKernel.php(60): NicklasW\PkmGoApi\Kernels\Kernel->initialize() #6 C:\xampp\htdocs\poke\src\Kernels\Kernel.php(40): NicklasW\PkmGoApi\Kernels\ApplicationKernel->initialize() #7 C:\xampp\htdocs\poke\src\Kernels\ApplicationKernel.php(46): NicklasW\PkmGoApi\Kernels\ in C:\xampp\htdocs\poke\vendor\vlucas\phpdotenv\src\Loader.php on line 75
Please Help me !
php examples\RetrievePlayerStatsExample.php
Fatal error: Uncaught exception 'Exception' with message 'Incorrect wire format for field 1, expected: 0 got: 2' in E:\OpenServer\domains\goapi\res\POGOProtos\Networking\Envelopes\ResponseEnvelope.php:153
Stack trace:
#0 E:\OpenServer\domains\goapi\src\Handlers\RequestHandler.php(181): POGOProtos\Networking\Envelopes\ResponseEnvelope->read('\n<html><head>\n<...')
#1 E:\OpenServer\domains\goapi\src\Handlers\RequestHandler.php(166): NicklasW\PkmGoApi\Handlers\RequestHandler->unmarshall(Object(GuzzleHttp\Psr7\Response))
#2 E:\OpenServer\domains\goapi\src\Handlers\RequestHandler.php(86): NicklasW\PkmGoApi\Handlers\RequestHandler->call(Object(POGOProtos\Networking\Envelopes\RequestEnvelope))
#3 E:\OpenServer\domains\goapi\src\Services\Request\InventoryRequestService.php(19): NicklasW\PkmGoApi\Handlers\RequestHandler->handle(Object(NicklasW\PkmGoApi\Requests\GetInventoryRequest))
#4 E:\OpenServer\domains\goapi\src\Api\Player\Inventory.php(37): NicklasW\PkmGoApi\Services\Request\InventoryRequestService->getInventory()
#5 E:\Open in E:\OpenServer\domains\goapi\res\POGOProtos\Networking\Envelopes\ResponseEnvelope.php on line 153
Hello there,
thank you for these fantastic API!
I've put all the files include the vendor directory into my website and modified the example php file "RetrievePlayerProfile.php" with my login.
When I run it, my browser said:
Parse error: syntax error, unexpected '[' in /home/puffo83/public_html/pokeapi/vendor/illuminate/support/helpers.php on line 358
but that line of code is perfect without error!
How can I fix it? Can you suggest me any guide? Thank you very much!
Im try to get stats and the pokemonCaughtByType is Rk����)��B1����,
$pokemonGoApi->getInventory()->getItems()->getStats()->getPokemonCaughtByType();
whats the encode should be?
Parse error: syntax error, unexpected 'UNSET' (T_UNSET), expecting identifier (T_STRING) or class (T_CLASS) in /home/gnat/www/oku.pl/PokemonGoAPI-PHP/vendor/nicklasw/pogoprotos-php/src/POGOProtos/Networking/Responses/ReleasePokemonResponse.php on line 45
You may want to add "prefer-stable": true
to your composer.json.
Hello again.. Not sure what is wrong here, but I get this message, when I try to get the Candy Amount
https://gyazo.com/5f46e52b21da40ae88c5aae83c690bf2
Thanks
After few days working on my local server, I tried to upload my project on a web server.
Everything works ok, I can read the player data, the inventory, pokebank.
But when I try to "release" a pokemon, I get an error.
On my local web server not. Only on the version I uploaded online.
Parse error: syntax error, unexpected 'UNSET' (T_UNSET), expecting identifier (T_STRING) in /mydomain.ext/res/POGOProtos/Networking/Responses/ReleasePokemonResponse.php on line 15
Note that the release action it's ok, if I go back to previous page where I list my pokemon, the Pokemon selected has been released succeffully.
But I still get this error that stops the redirecting action.
Dotenv\Exception\InvalidPathException with message 'Unable to read the environment file at .../vendor/nicklasw/pkm-go-api/src/Kernels/../../.env.'
Why does the package use an .env file for the config variables? It makes it impossible to install the package with "composer require nicklasw/pkm-go-api". The only workaround to prevent this error is to modify files in composers vendor dir. Or do I miss something?
In PokemonGoAPI-PHP/res/POGOProtos/Networking/Requests/RequestType.php
on line 76 there is const ECHO = 666;
.
On php 5.6.24-1
it creates parse error, because echo is reserved keyword.
Hello !
First, thanks for this API !
I try this with my login:
$application = new ApplicationKernel('EMAIL', 'PASSWORD', Factory::AUTHENTICATION_TYPE_GOOGLE);
And I had this arror:
Fatal error: Uncaught exception 'NicklasW\PkmGoApi\Authenticators\Exceptions\AuthenticationException' with message 'Invalid user credentials. Response: 'Error=NeedsBrowser Url=https://accounts.google.com/signin/continue?... ErrorDetail=To access your account, you must sign in on the web. Touch Next to start browser sign-in.'
So, someone can help me ? I have to log me in the browser. I don't understand this error.
When I try to run the example's I either get 502 error or Invalid authentication token,
any ideas?
Thanks
Hello there,
Is there any method/function to scan your local area for looking for PokeStops, Pokemons or Gyms?
Thank you so much!
Hey, I get this everytime I try to run a file, any suggestions?
https://gyazo.com/e56ab03acbd6aa9cb2acbbb50bf317f3
Thanks in advance.
With a fresh install, I tried to up RetrievePokemonCountExample.php (after updating the auth info) and get the error below:
PHP Fatal error: Uncaught exception 'Exception' with message 'read_bytes(): Unexpected end of stream' in vendor/nicklasw/pogoprotos-php/src/protocolbuffers.inc.php:364
This happens with many of the other example scripts as well.
I saw that in this latest release there are useful information about Pokemons in PokemonMeta.php and PokemonMetaRegistry.php files.
My question now is: how to call these infos once we have our Pokemons get from PokeBank?
I'd need to read the $pokemonMeta->getCandyToEvolve();
After login is successful I'm getting a complete empty array from this function?
$inventory = $pokemonGoApi->getInventory();
You got any contact information? Skype?
[Suggestion] Pokemon IV perfection, Candy, Stardust
/**
* Returns a sorted collection by Date Captured.
*
* @param bool $descending
* @return static
*/
public function sortByDate($descending = false)
{
return $this->sortBy(function (Pokemon $pokemon1) {
return $pokemon1->getCreationTimeMs();
}, SORT_REGULAR, $descending);
}
With this add in PokemonCollection.php you can sort Pokemon list by Date captured (creationTime)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.