Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
DrDelay edited this page Aug 14, 2016 · 2 revisions

This probably cannot cover everything, but I'll try to give you a "head-start" by clearing up some basics.

Auth 1

Login (Google or Ptc) is not part of this repository. You have to authenticate at certain endpoints using "plain" HTTP-requests.

Example with Ptc (client is a Guzzle-Client, validations removed to make it shorter):

    const PTC_LOGIN_URL = 'https://sso.pokemon.com/sso/login?service=https%3A%2F%2Fsso.pokemon.com%2Fsso%2Foauth2.0%2FcallbackAuthorize';
    const PTC_OAUTH_URL = 'https://sso.pokemon.com/sso/oauth2.0/accessToken';
    const PTC_OAUTH_CLIENT_ID = 'mobile-app_pokemon-go';
    const PTC_OAUTH_REDIRECT = 'https://www.nianticlabs.com/pokemongo/error';
    const PTC_OAUTH_CLIENT_SECRET = 'w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR';

(...)

        $session = json_decode($this->client->get(static::PTC_LOGIN_URL)->getBody());

        $login = $this->client->post(static::PTC_LOGIN_URL, [
            'form_params' => [
                'lt' => $session->lt,
                'execution' => $session->execution,
                '_eventId' => 'submit',
                'username' => $this->username,
                'password' => $this->password,
            ],
        ]);
        $ticketRedirect = $login->getHeaderLine('Location');
        (...)
        parse_str(parse_url($ticketRedirect, PHP_URL_QUERY), $queryParts);
        (...)
        $ticket = $queryParts['ticket'];

        $token = $this->client->post(static::PTC_OAUTH_URL, [
            'form_params' => [
                'client_id' => static::PTC_OAUTH_CLIENT_ID,
                'redirect_uri' => static::PTC_OAUTH_REDIRECT,
                'client_secret' => static::PTC_OAUTH_CLIENT_SECRET,
                'grant_type' => 'refresh_token',
                'code' => $ticket,
            ],
        ]);
        parse_str($token->getBody(), $tokenParts);
        (...)
        // $tokenParts['access_token'] contains the token
        // $tokenParts['expires'] its lifetime in seconds, if you want to cache it

The token will be something like TGT-4426529-bj1ab0gqu2lNIexyyZruj5tkoBZCV67dLEEaR2cKIqzTYwBg2q-sso.pokemon.com.

From Google you'll need an so called id_token, this is a considerably longer one. There are many examples for Google OAuth in the web (the playground is cool). You may look at this (not tested) for a basic authentication flow with username/password, or NicklasWallgren/PokemonGoAPI-PHP#54 for an OAuth solution.

Basic Request/Response

Put simply, you instantiate a POGOProtos\Networking\Envelopes\RequestEnvelope, fill it with contents, use its toStream-method to send it. Then pass the Response-Stream into the constructor of \POGOProtos\Networking\Envelopes\ResponseEnvelope.

Of course, there are lots of thing you should consider: Status Codes, Handshakes, Throttling, Auth-Lifetimes, ...

Auth 2

You'll need an AuthTicket and endpoint URL, you can receive that by sending a POGOProtos\Networking\Envelopes\RequestEnvelope\AuthInfo with your token, set by $env->setAuthInfo($auth). Save the returned AuthTicket and use it on subsequent requests!

Requests

You can set your requests (what you want to get with this call) using the addRequests-method of the RequestEnvelope, providing a \POGOProtos\Networking\Requests\Request. You can simply instantiate one and do setRequestType, providing a \POGOProtos\Networking\Requests\RequestType (this is a simple enum).

Responses

The ResponseEnvelope has a getReturnsList-method to get the responses for each request. You should pass them into the constructor of the relevant response-class. E.g. GET_PLAYER goes to POGOProtos\Networking\Responses\GetPlayerResponse.

Clone this wiki locally