Search code examples
phpapitwitterzend-framework2

Cannot get derived property from ZF2 Twitter user search


I'm using ZF2 Twitter package to get user info by username and retrieve it's location, but the returned object doesn't give me the "derived" property, that should have the detailed data about location I want to use.

public function twitterAction()
{
    $config = array(
        'access_token' => array(
            'token' => 'MY TOKEN',
            'secret' => 'MY SECRET',
        ),
        'oauth_options' => array(
            'consumerKey' => 'MY CONSUMER KEY',
            'consumerSecret' => 'MY COMSUMER SECRET',
        ),
        'http_client_options' => array(
            'adapter' => 'Zend\Http\Client\Adapter\Curl',
            'curloptions' => array(
                CURLOPT_SSL_VERIFYHOST => false,
                CURLOPT_SSL_VERIFYPEER => false,
            ),
        ),
    );
    $twitter = new Twitter($config);
    $response = $twitter->account->accountVerifyCredentials();
    if (!$response->isSuccess()) {
        die(var_dump($response->getErrors()));
    }
    $params = $this->params()->fromRoute();
    $profile = $params['profile'];
    $user = $twitter->users->show($profile);
    $coordinates = $user->derived->geo->coordinates;

    return new JsonModel(
     [
         'placeName' => $user->derived->locality . ' - ' $user->derived->region,
         'link' => 'http://www.google.com/maps/place/'.$coordinates[0].','.$coordinates[1]
     ]
 );
}

I'm using the twitter api page as reference

this is the response I get if I return the user

{
    'placename: ': '-',
    'link: ': 'http://www.google.com/maps/place/,',
}

How can I retrieve this data?


Solution

  • From that page:

    Profile Geo data will be included in Twitter's PowerTrack, Replay, Volume Stream, Search, and Historical PowerTrack APIs.

    I think that means the geo data is only available for paying customers of PowerTrack. If you're just a regular developer, you can't get it.