Giter Club home page Giter Club logo

pokemongoapi-php's Introduction

PokemonGoAPI-PHP

Total Downloads PHP7 Ready

Pokemon GO PHP API library

Install

Run the command composer require nicklasw/pkm-go-api.

Usage

EG:

 // Create the authentication config
$config = new Config();
$config->setProvider(Factory::PROVIDER_PTC);
$config->setUser('INSERT_USER');
$config->setPassword('INSERT_PASSWORD');

// Create the authentication manager
$manager = Factory::create($config);

// Add a event listener,
$manager->addListener(function ($event, $value) {
    if ($event === Manager::EVENT_ACCESS_TOKEN) {
        /** @var AccessToken $accessToken */
        $accessToken = $value;

        // Persist the access token in session storage, cache or whatever.
    }
});

// Initialize the pokemon go application
$application = new ApplicationKernel($manager);

// Retrieve the pokemon go api instance
$pokemonGoApi = $application->getPokemonGoApi();

// Retrieve the inventory
$inventory = $pokemonGoApi->getInventory();

// Retrieve the poke bank
$pokeBank = $inventory->getPokeBank();

// Retrieve a pokemon of type pidgey
$pokemon = $pokeBank->getPokemonsByType(PokemonId::PIDGEY)->first();

// Transfer / Release the pokemon (Send to the meat grinder)
$pokemon->transfer();

TODO

  • Implement the Map API
  • Improve logging

Contributors

Testing

$ composer test

Slack Chat

We use Slack for community discussions. You can find our team here: https://pokemongoapi-php.slack.com

Credits

pokemongoapi-php's People

Contributors

cdeveau avatar drdelay avatar f2008305 avatar gnacik avatar mattwells avatar ni42 avatar nicklaswallgren avatar voxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pokemongoapi-php's Issues

RequestType.php ECHO_REQUEST changed

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.

For the beginner

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!

pokemonfamilyid

the pokemonfamiliy id is missing. so we can't get candy using that value now

Suggestion: sort invetory pokemon

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)

Error - Unexpected end of stream

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.

Help: How to get the OAuth token from this token

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 ?

Google Authentication Failing

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

Empty Response

After login is successful I'm getting a complete empty array from this function?

$inventory = $pokemonGoApi->getInventory();

You got any contact information? Skype?

Scan area for objects

Hello there,
Is there any method/function to scan your local area for looking for PokeStops, Pokemons or Gyms?
Thank you so much!

Error with Google auth

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.

get current Trainer exp level

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)

immagine

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?

Parse error: syntax error, unexpected 'UNSET' (T_UNSET)

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

ReleasePokemonResponse syntax error

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.

getPokemonFabilyId doesn't work every time

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.

candy1
candy2

Warning: require(C:\xampp\htdocs\poke\examples/../vendor/autoload.php): failed to open

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

Get all pokemon one by one

Hello !

How can I retrieve all pokemon one by one ?

for example like this:

foreach($allPokemon => $pokemon){ echo $pokemon->getName(); }

Thank you !

pokemonMeta

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();

OAuth support?

Hello,

not thought about adding logins using OAuth from Google?

Thanks

InvalidPathException with message 'Unable to read the environment file at .env

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?

getPokedexItems is empty

$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.

Not work auth with Google and PTC

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
"
image

What the problem?

attacks and damages

are in the code the attacks and damages of a pokemon?
or can we have only the id of that attack?

How to use this ?

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

Get the type of pokemon

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 !

Parse error: syntax error, unexpected '['

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!

Always have an issue on 'use' keyword

example:

require DIR . '/../vendor/autoload.php';
use NicklasW\PkmGoApi\Authenticators\Factory;
use NicklasW\PkmGoApi\Kernels\ApplicationKernel;
use POGOProtos\Enums\PokemonId;

** what does it mean?

Fatal error: Uncaught exception

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 !

Is there a way to get Pokemon by cp?

$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

'Invalid authentication token provided'

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] => )

get Pokedex info about missing Pokemon

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

Evolving check

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.

ReleasePokemonResponse bug

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

How to get value of Stardust and pokecoins

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();
        });

Sort PokemonCollection by Date

/**
     * 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)

PHP Parse error

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.

Example Error

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.