Skip to content

Commit

Permalink
Merge pull request #1128 from hybridauth/ApacheEx-patch-1
Browse files Browse the repository at this point in the history
[Twitter] Make photo size configurable + https
  • Loading branch information
ApacheEx committed Dec 13, 2019
2 parents b2a02f5 + 587623a commit 06909cd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions hybridauth/Hybrid/Providers/Twitter.php
Expand Up @@ -112,7 +112,7 @@ function getUserProfile() {
$includeEmail = isset($this->config['includeEmail']) ? (bool) $this->config['includeEmail'] : false;
$response = $this->api->get('account/verify_credentials.json'. ($includeEmail ? '?include_email=true' : ''));

// check the last HTTP status code returned
// check the last HTTP status code returned.
if ($this->api->http_code != 200) {
throw new Exception("User profile request failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus($this->api->http_code), 6);
}
Expand All @@ -121,12 +121,17 @@ function getUserProfile() {
throw new Exception("User profile request failed! {$this->providerId} api returned an invalid response: " . Hybrid_Logger::dumpData( $response ), 6);
}

# store the user profile.
// store the user profile.
$this->user->profile->identifier = (property_exists($response, 'id')) ? $response->id : "";
$this->user->profile->displayName = (property_exists($response, 'screen_name')) ? $response->screen_name : "";
$this->user->profile->description = (property_exists($response, 'description')) ? $response->description : "";
$this->user->profile->firstName = (property_exists($response, 'name')) ? $response->name : "";
$this->user->profile->photoURL = (property_exists($response, 'profile_image_url')) ? (str_replace('_normal', '', $response->profile_image_url)) : "";

// see https://developer.twitter.com/en/docs/accounts-and-users/user-profile-images-and-banners.
$photo_size = isset($this->config['photo_size']) ? $this->config['photo_size'] : 'original';
$photo_size = $photo_size === 'original' ? '' : "_{$photo_size}";
$this->user->profile->photoURL = (property_exists($response, 'profile_image_url_https')) ? (str_replace('_normal', $photo_size, $response->profile_image_url_https)) : "";

$this->user->profile->profileURL = (property_exists($response, 'screen_name')) ? ("http://twitter.com/" . $response->screen_name) : "";
$this->user->profile->webSiteURL = (property_exists($response, 'url')) ? $response->url : "";
$this->user->profile->region = (property_exists($response, 'location')) ? $response->location : "";
Expand Down

0 comments on commit 06909cd

Please sign in to comment.