Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $parameters = ['uid' => $this->token('user_id'), 'fields' => 'first_name,last_name,nickname,screen_name,sex,' . 'bdate,timezone,photo_rec,photo_big,photo_max_orig'];
     $response = $this->apiRequest('users.get', 'GET', $parameters);
     $data = new Data\Collection($response->response[0]);
     if (!$data->exists('uid')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('uid');
     $userProfile->email = $this->token('email');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->displayName = $data->get('screen_name');
     $userProfile->photoURL = $data->get('photo_max_orig');
     $userProfile->profileURL = $data->get('screen_name') ? 'http://vk.com/' . $data->get('screen_name') : '';
     if ($data->exists('sex')) {
         switch ($data->get('sex')) {
             case 1:
                 $userProfile->gender = 'female';
                 break;
             case 2:
                 $userProfile->gender = 'male';
                 break;
         }
     }
     return $userProfile;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function getUserContacts()
 {
     $contacts = [];
     $parameters = ['cursor' => '-1'];
     $response = $this->apiRequest('friends/ids.json', 'GET', $parameters);
     $data = new Data\Collection($response);
     if (!$data->exists('ids')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     if ($data->filter('ids')->isEmpty()) {
         return $contacts;
     }
     // 75 id per time should be okey
     $contactsIds = array_chunk((array) $data->get('ids'), 75);
     foreach ($contactsIds as $chunk) {
         $parameters = ['user_id' => implode(',', $chunk)];
         try {
             $response = $this->apiRequest('users/lookup.json', 'GET', $parameters);
             $data = (new Parser($response))->toCollection();
         } catch (Exception $e) {
             continue;
         }
         foreach ($data->all() as $item) {
             $contacts[] = $this->fetchUserContacts($item);
         }
     }
     return $contacts;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('people/me');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->firstName = $data->filter('name')->get('givenName');
     $userProfile->lastName = $data->filter('name')->get('familyName');
     $userProfile->displayName = $data->get('displayName');
     $userProfile->photoURL = $data->get('image');
     $userProfile->profileURL = $data->get('url');
     $userProfile->description = $data->get('aboutMe');
     $userProfile->gender = $data->get('gender');
     $userProfile->language = $data->get('language');
     $userProfile->email = $data->get('email');
     $userProfile->phone = $data->get('phone');
     $userProfile->country = $data->get('country');
     $userProfile->region = $data->get('region');
     $userProfile->zip = $data->get('zip');
     if ($data->filter('image')->exists('url')) {
         $userProfile->photoURL = substr($data->filter('image')->get('url'), 0, -2) . 150;
     }
     $userProfile = $this->fetchUserEmail($userProfile, $data);
     $userProfile = $this->fetchUserProfileUrl($userProfile, $data);
     $userProfile = $this->fetchBirthday($userProfile, $data->get('birthday'));
     $userProfile->emailVerified = $data->get('verified') ? $userProfile->email : '';
     return $userProfile;
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('me.json');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->displayName = $data->get('name');
     $userProfile->profileURL = 'https://www.reddit.com/user/' . $data->get('name') . '/';
     return $userProfile;
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('userdata');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->firstName = $data->get('firstName');
     $userProfile->displayName = $data->get('firstName');
     $userProfile->email = $data->get('email');
     $userProfile->emailVerified = $data->get('email');
     return $userProfile;
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users/self/');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $data = $data->filter('id');
     $userProfile->identifier = $data->get('id');
     $userProfile->description = $data->get('bio');
     $userProfile->photoURL = $data->get('profile_picture');
     $userProfile->webSiteURL = $data->get('website');
     $userProfile->displayName = $data->get('full_name');
     $userProfile->displayName = $userProfile->displayName ?: $data->get('username');
     return $userProfile;
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users/me');
     $data = new Data\Collection($response);
     if (!$data->exists('user')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $data = $data->get('user');
     $userProfile->identifier = str_ireplace($this->apiBaseUrl . 'users/', '', $data->get('url'));
     $userProfile->description = $data->get('role');
     $userProfile->email = $data->get('email');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->displayName = trim(${$data}->get('first_name') . ' ' . $data->get('last_name'));
     return $userProfile;
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('me/');
     $data = new Data\Collection($response);
     if (!$data->exists('ID')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('ID');
     $userProfile->displayName = $data->get('display_name');
     $userProfile->photoURL = $data->get('avatar_URL');
     $userProfile->profileURL = $data->get('profile_URL');
     $userProfile->email = $data->get('email');
     $userProfile->language = $data->get('language');
     $userProfile->displayName = $userProfile->displayName ?: $data->get('username');
     $userProfile->emailVerified = 1 == $data->get('email_verified') ? $data->get('email') : '';
     return $userProfile;
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('user');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->profileURL = $data->get('html_url');
     $userProfile->photoURL = $data->get('avatar_url');
     $userProfile->description = $data->get('bio');
     $userProfile->region = $data->get('location');
     $userProfile->displayName = $data->get('name');
     $userProfile->displayName = $userProfile->displayName ?: $data->get('username');
     $userProfile->webSiteURL = $data->filter('links')->get('web');
     return $userProfile;
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users.getInfo');
     $data = new Data\Collection($response[0]);
     if (!$data->exists('uid')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('uid');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->displayName = $data->get('nick');
     $userProfile->photoURL = $data->get('pic');
     $userProfile->profileURL = $data->get('link');
     $userProfile->gender = $data->get('sex');
     $userProfile->email = $data->get('email');
     $userProfile->emailVerified = $data->get('email');
     return $userProfile;
 }
Exemple #11
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $fields = ['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-url', 'public-profile-url'];
     $response = $this->apiRequest('people/~:(' . implode(',', $this->fields) . ')?format=json');
     $data = new Data\Collection($response);
     if (!$data->exists('ID')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('ID');
     $userProfile->firstName = $data->get('firstName');
     $userProfile->lastName = $data->get('lastName');
     $userProfile->photoURL = $data->get('pictureUrl');
     $userProfile->profileURL = $data->get('publicProfileUrl');
     $userProfile->email = $data->get('headline');
     $userProfile->bio = $data->get('language');
     $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName);
     return $userProfile;
 }
Exemple #12
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $fields = array('uid', 'locale', 'first_name', 'last_name', 'name', 'gender', 'age', 'birthday', 'has_email', 'current_status', 'current_status_id', 'current_status_date', 'online', 'photo_id', 'pic_1', 'pic_2', 'pic1024x768', 'location', 'email');
     $sig = md5('application_key=' . $this->config->get('keys')['key'] . 'fields=' . implode(',', $fields) . 'method=users.getCurrentUser' . md5($this->token('access_token') . $this->config->get('keys')['secret']));
     $parameters = ['application_key' => $this->config->get('keys')['key'], 'method' => 'users.getCurrentUser', 'fields' => implode(',', $fields), 'sig' => $sig];
     $response = $this->apiRequest('', 'GET', $parameters);
     $data = new Data\Collection($response);
     if (!$data->exists('uid')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('uid');
     $userProfile->email = $data->get('email');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->displayName = $data->get('name');
     $userProfile->photoURL = $data->get('pic1024x768');
     $userProfile->profileURL = 'http://ok.ru/profile/' . $data->get('uid');
     return $userProfile;
 }
Exemple #13
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('me');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->displayName = $data->get('name');
     $userProfile->firstName = $data->get('first_name');
     $userProfile->lastName = $data->get('last_name');
     $userProfile->gender = $data->get('gender');
     $userProfile->profileURL = $data->get('link');
     $userProfile->email = $data->filter('emails')->get('preferred');
     $userProfile->emailVerified = $data->filter('emails')->get('account');
     $userProfile->birthDay = $data->get('birth_day');
     $userProfile->birthMonth = $data->get('birth_month');
     $userProfile->birthYear = $data->get('birth_year');
     return $userProfile;
 }
Exemple #14
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $data = $data->filter('user');
     $userProfile->identifier = $data->get('id');
     $userProfile->displayName = $data->get('username');
     $userProfile->description = $data->get('about');
     $userProfile->firstName = $data->get('firstname');
     $userProfile->lastName = $data->get('lastname');
     $userProfile->photoURL = $data->get('userpic_url');
     $userProfile->city = $data->get('city');
     $userProfile->region = $data->get('state');
     $userProfile->country = $data->get('country');
     $userProfile->profileURL = $data->exists('domain') ? 'http://' . $data->get('domain') : '';
     return $userProfile;
 }
Exemple #15
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('user');
     $data = new Data\Collection($response);
     if (!$data->exists('id')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->identifier = $data->get('id');
     $userProfile->displayName = $data->get('name');
     $userProfile->description = $data->get('bio');
     $userProfile->photoURL = $data->get('avatar_url');
     $userProfile->profileURL = $data->get('html_url');
     $userProfile->email = $data->get('email');
     $userProfile->webSiteURL = $data->get('blog');
     $userProfile->region = $data->get('location');
     $userProfile->displayName = $userProfile->displayName ?: $data->get('login');
     if (empty($userProfile->email) && strpos($this->scope, 'user:email') !== false) {
         $userProfile = $this->requestUserEmail($userProfile);
     }
     return $userProfile;
 }
Exemple #16
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('user/info');
     $data = new Data\Collection($response);
     if (!$data->exists('response')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $userProfile->displayName = $data->filter('response')->filter('user')->get('name');
     foreach ($data->filter('response')->filter('user')->filter('blogs')->all() as $blog) {
         if ($blog->get('primary') && $blog->exists('url')) {
             $userProfile->identifier = $blog->get('url');
             $userProfile->profileURL = $blog->get('url');
             $userProfile->webSiteURL = $blog->get('url');
             $userProfile->description = strip_tags($blog->get('description'));
             $bloghostname = explode('://', $blog->get('url'));
             $bloghostname = substr($bloghostname[1], 0, -1);
             $this->token('primary_blog', $bloghostname);
             break;
         }
     }
     return $userProfile;
 }
Exemple #17
0
 /**
  * {@inheritdoc}
  */
 public function getUserProfile()
 {
     $response = $this->apiRequest('users/self');
     $data = new Data\Collection($response);
     if (!$data->exists('response')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     $userProfile = new User\Profile();
     $data = $data->filter('response')->filter('user');
     $userProfile->identifier = $data->get('id');
     $userProfile->firstName = $data->get('firstName');
     $userProfile->lastName = $data->get('lastName');
     $userProfile->gender = $data->get('gender');
     $userProfile->city = $data->get('homeCity');
     $userProfile->email = $data->filter('contact')->get('email');
     $userProfile->emailVerified = $userProfile->email;
     $userProfile->profileURL = 'https://www.foursquare.com/user/' . $userProfile->identifier;
     $userProfile->displayName = trim($userProfile->firstName . ' ' . $userProfile->lastName);
     if ($data->exists('photo')) {
         $userProfile->photoURL = $data->filter('photo')->get('prefix') . '150x150' . $data->filter('photo')->get('suffix');
     }
     return $userProfile;
 }
Exemple #18
0
 /**
  * {@inheritdoc}
  */
 public function getUserActivity($stream)
 {
     $activities = [];
     $apiUrl = $stream == 'me' ? '/me/feed' : '/me/home';
     $response = $this->apiRequest($apiUrl);
     $data = new Data\Collection($response);
     if (!$data->exists('data')) {
         throw new UnexpectedValueException('Provider API returned an unexpected response.');
     }
     if ($data->filter('data')->isEmpty()) {
         return $activities;
     }
     foreach ($data->filter('data')->all() as $item) {
         $activities[] = $this->fetchUserActivity($item);
     }
     return $activities;
 }
Exemple #19
0
 /**
  * Validate Access Token Response
  *
  * RFC6749: If the access token request is valid and authorized, the
  * authorization server issues an access token and optional refresh token.
  * If the request client authentication failed or is invalid, the authorization
  * server returns an error response as described in Section 5.2.
  *
  * Example of a successful response:
  *
  *  HTTP/1.1 200 OK
  *  Content-Type: application/json;charset=UTF-8
  *  Cache-Control: no-store
  *  Pragma: no-cache
  *
  *  {
  *      "access_token":"2YotnFZFEjr1zCsicMWpAA",
  *      "token_type":"example",
  *      "expires_in":3600,
  *      "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
  *      "example_parameter":"example_value"
  *  }
  *
  * http://tools.ietf.org/html/rfc6749#section-4.1.4
  *
  * This method uses Data_Parser to attempt to decodes the raw $response (usually JSON)
  * into a data collection.
  *
  * @param string $response
  *
  * @return \Hybridauth\Data\Collection
  * @throws InvalidAccessTokenException
  */
 protected function validateAccessTokenExchange($response)
 {
     $data = (new Data\Parser())->parse($response);
     $collection = new Data\Collection($data);
     if (!$collection->exists('access_token')) {
         throw new InvalidAccessTokenException('Provider returned an invalid access_token: ' . htmlentities($response));
     }
     $this->token('access_token', $collection->get('access_token'));
     $this->token('token_type', $collection->get('token_type'));
     $this->token('refresh_token', $collection->get('refresh_token'));
     $this->token('expires_in', $collection->get('expires_in'));
     // calculate when the access token expire
     if ($collection->exists('expires_in')) {
         $expires_at = time() + (int) $collection->get('expires_in');
         $this->token('access_token_expires_at', $expires_at);
     }
     $this->deleteToken('authorization_state');
     return $collection;
 }
Exemple #20
0
 /**
  * Validate Access Token Response
  *
  * OAuth Core: If successful, the Service Provider generates an Access Token and Token Secret and returns
  * them in the HTTP response body.
  *
  * The Access Token and Token Secret are stored by the Consumer and used when signing Protected Resources requests.
  *
  * http://oauth.net/core/1.0a/#auth_step3
  * 6.3.2. Service Provider Grants an Access Token
  *
  * @param string $response
  *
  * @return \Hybridauth\Data\Collection
  * @throws InvalidAccessTokenException
  */
 protected function validateAccessTokenExchange($response)
 {
     /**
      * The response contains the following parameters:
      *
      *    - oauth_token         The Access Token.
      *    - oauth_token_secret  The Token Secret.
      *
      * http://oauth.net/core/1.0/#auth_step3
      * 6.3.2. Service Provider Grants an Access Token
      *
      * Example of a successful response:
      *
      *  HTTP/1.1 200 OK
      *  Content-Type: text/html; charset=utf-8
      *  Cache-Control: no-store
      *  Pragma: no-cache
      *
      *  oauth_token=sHeLU7Far428zj8PzlWR75&oauth_token_secret=fXb30rzoG&oauth_callback_confirmed=true
      *
      * OAuthUtil::parse_parameters will attempt to decode the raw response into an array.
      */
     $tokens = OAuthUtil::parse_parameters($response);
     $collection = new Data\Collection($tokens);
     if (!$collection->exists('oauth_token')) {
         throw new InvalidAccessTokenException('Provider returned an invalid access_token: ' . htmlentities($response));
     }
     $this->consumerToken = new OAuthConsumer($collection->get('oauth_token'), $collection->get('oauth_token_secret'));
     $this->token('access_token', $collection->get('oauth_token'));
     $this->token('access_token_secret', $collection->get('oauth_token_secret'));
     $this->deleteToken('request_token');
     $this->deleteToken('request_token_secret');
     return $collection;
 }