A
A
Alexander Grishchenko2016-03-28 21:56:06
PHP
Alexander Grishchenko, 2016-03-28 21:56:06

Authorization using Hybridauth. Vkontakte sends ID instead of username?

Good day to all. Site on Wordpress. The Commentator plugin is installed, which uses the Hybridauth library for user authorization. I added the entrance using Vkontakte myself.
Vkontakte.php - Github
Everything works but displays ID instead of name:
d18ecaefdb42433cbf07958750579f11.png

function getUserProfile()
  {
    // refresh tokens if needed
    $this->refreshToken();
    // Vkontakte requires user id, not just token for api access
    $params['uid'] = Hybrid_Auth::storage()->get( "hauth_session.{$this->providerId}.user_id" );
    $params['fields'] = implode(',', $this->fields);
    // ask vkontakte api for user infos
    $response = $this->api->api( 'getProfiles' , 'GET', $params);
    if (!isset( $response->response[0] ) || !isset( $response->response[0]->uid ) || isset( $response->error ) ){
      throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
    }
    // Fill datas
    $response = reset($response->response);
    foreach ($this->getUserByResponse($response, true) as $k => $v)
      $this->user->profile->$k = $v;
    // Additional data
    $this->user->profile->email = Hybrid_Auth::storage()->get( "hauth_session.{$this->providerId}.user_email" );
    return $this->user->profile;
  }

I can’t find on the Internet what exactly needs to be added or corrected here so that the user’s first and last name is displayed, and not his ID. The thing is - $response = $this->api->api( 'getProfiles' , 'GET', $params);
or somewhere here you need to add extra. parameters - $this->user->profile-> . Sorry, PHP hasn't even started learning yet, so it's hard for now). Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question