NicklasWallgren / PokemonGoAPI-PHP

Pokemon Go API PHP library
BSD 2-Clause "Simplified" License
130 stars 51 forks source link

ResponseException: Retrieved a invalid response. Response code: '403' #157

Closed sebast1219 closed 7 years ago

sebast1219 commented 7 years ago

PHP Fatal error: Uncaught NicklasW\PkmGoApi\Handlers\RequestHandler\Exceptions\ResponseException: Retrieved a invalid response. Response code: '403' in /var/www/dev/ pokemap/api/src/Handlers/RequestHandler.php:425 Stack trace:

0 /var/www/dev/pokemap/api/src/Handlers/RequestHandler.php(264): NicklasW\PkmGoApi\Handlers\RequestHandler->validateResponse(Object(GuzzleHttp\Psr7\Response))

1 /var/www/dev/pokemap/api/src/Handlers/RequestHandler.php(122): NicklasW\PkmGoApi\Handlers\RequestHandler->call(Object(POGOProtos\Networking\Envelopes\RequestEnvelo pe))

2 /var/www/dev/pokemap/api/src/Services/Request/PlayerRequestService.php(20): NicklasW\PkmGoApi\Handlers\RequestHandler->handle(Object(NicklasW\PkmGoApi\Requests\Get PlayerRequest))

3 /var/www/dev/pokemap/api/src/Api/Player/Profile.php(58): NicklasW\PkmGoApi\Services\Request\PlayerRequestService->getPlayer()

4 /var/www/dev/pokemap/api/src/Api/Procedure.php(36): NicklasW\PkmGoApi\Api\Player\Profile->update()

5 /var/www/dev/pokemap/api/src/Api/Player/Profile.php(49): NicklasW\Pk in /var/www/dev/pokemap/api/src/Handlers/RequestHandler.php on line 425

Could you invite me on Slack to discuss? my mail : seb_19@hotmail.fr

voxx commented 7 years ago

I just tested examples/RetrievePlayerProfileExample.php from a fresh pull and I'm able to pull player profile without error.

Are you using latest source, and are you using the example code or your own implementation?

sebast1219 commented 7 years ago

I downloaded the source this morning so yeah. Hear my source code for test

<?php

require DIR . '/../vendor/autoload.php';

use GuzzleHttp\Client; use NicklasW\PkmGoApi\Authentication\Config\Config; use NicklasW\PkmGoApi\Authentication\Factory\Factory; use NicklasW\PkmGoApi\Kernels\ApplicationKernel; use GuzzleHttp\RequestOptions;

class ApiExample {

/**
 * Run the example.
 */
public function run()
{
    // Create the authentication config
    $config = new Config();
    // $config->setProvider(Factory::PROVIDER_PTC);
    // $config->setUser('INSERT_USER');
    // $config->setPassword('INSERT_PASSWORD');
    // $config->setProvider(Factory::PROVIDER_GOOGLE);
    $config->setProvider(Factory::PROVIDER_PTC);
    $config->setUser('scanCholet001');
    $config->setPassword('123456789');

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

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

    // Pass a custom client to the library
    // $application->setClient(new Client(array(RequestOptions::PROXY => 'INSERT_PROXY')));

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

    // Retrieve the profile
    $profile = $pokemonGoApi->getProfile();

    // Retrieve the profile data
    $profileData = $profile->getData();

    echo sprintf('The profile data: %s', print_r($profileData, true));
}

}

$example = new ApiExample(); $example->run();

voxx commented 7 years ago

Looks to be an issue with guzzle?

I've just tested with examples/RetrievePlayerProfileExample.php using your credentials above (you probably shouldnt post your credentials in public) and pulled player profile data without error.

The profile data: NicklasW\PkmGoApi\Api\Player\Data\Profile\ProfileData Object ( [creationTime:protected] => 1477564447441 [username:protected] => seb_19+scanCholet001 [team:protected] => 0 [tutorialState:protected] => NicklasW\PkmGoApi\Api\Player\Data\Profile\TutorialState Object ( [state:protected] => Array ( ) ) [avatar:protected] => [pokemonStorage:protected] => 250 [itemStorage:protected] => 350 [dailyBonus:protected] => NicklasW\PkmGoApi\Api\Player\Data\Profile\DailyBonus Object ( [nextCollectedTimestampMs:protected] => 0 [nextDefenderBonusCollectTimestampMs:protected] => 0 ) [badge:protected] => NicklasW\PkmGoApi\Api\Player\Data\Profile\Badge Object ( [badgeType:protected] => 0 [level:protected] => 0 [nextEquipChangeAllowedTimestampMs:protected] => 0 ) [contactSettings:protected] => NicklasW\PkmGoApi\Api\Player\Data\Profile\ContactSettings Object ( [sendMarketingEmails:protected] => [sendPushNotifications:protected] => ) [currencies:protected] => NicklasW\PkmGoApi\Api\Player\Data\Profile\Currencies Object ( [currencies:protected] => Array ( [POKECOIN] => NicklasW\PkmGoApi\Api\Player\Data\Profile\Currency Object ( [name:protected] => POKECOIN [amount:protected] => 0 ) [STARDUST] => NicklasW\PkmGoApi\Api\Player\Data\Profile\Currency Object ( [name:protected] => STARDUST [amount:protected] => 0 ) ) ) )

sebast1219 commented 7 years ago

That's just a test account so no problem here. That could be a problem from my IP?

voxx commented 7 years ago

Can you test pulling profile data with the default example provided? (not your customized code)

403 error is typically an "access denied" server response, indicating you may be attempting to make the call from a banned ip address.

sebast1219 commented 7 years ago

Same with the original code, will try with another ip ;)

voxx commented 7 years ago

@sebast1219

Can you confirm test with example works or throws same 403 error to verify this issue is related to your originating ip being banned/blocked and not the api.

Can you also close out this issue when you've verified the issue is not API related as we've speculated.

Thanks! -VOXX

DrDelay commented 7 years ago

This could very likely be an IP ban, where is the machine located you are using? A VPS hoster like DigitalOcean?

See also https://github.com/NicklasWallgren/PokemonGoAPI-PHP/issues/105#issuecomment-239661861 / https://github.com/NicklasWallgren/PokemonGoAPI-PHP/issues/76

sebast1219 commented 7 years ago

I will test it today i think! that's a VPS hosted on OVH. Will tell you if it works or not with a new IP

NicklasWallgren commented 7 years ago

@sebast1219 Have you made any progress?, can we resolve this issue?

sebast1219 commented 7 years ago

Hi! I'm using nodejs API now... But yes that was OVH IP blacklisted by niantic ;)

NicklasWallgren commented 7 years ago

Resolved.