-
Notifications
You must be signed in to change notification settings - Fork 8
Usage
This probably cannot cover everything, but I'll try to give you a "head-start" by clearing up some basics.
I suggest you to use the "new" Protobuf-plugin as discussed in #8 , it seems to be a lot cleaner, without having the fiddle in the vendors code to fix some bugs. I have it required like this in my composer.json until it is officially merged and tagged:
"jaspervdm/pogoprotos-php": "dev-test-protobuf#c9ac6ddee52217e75b142fae355250c5edba62e7",
These usage instructions will be about the "new" version, the differences are very small, though.
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, validation 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 itThe 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.
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, ...
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!
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).
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.