TwitterOAuth1Service.php
1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* An example of extending the provider class.
*
* @author Maxim Zemskov <nodge@yandex.ru>
* @link http://github.com/Nodge/yii2-eauth/
* @license http://www.opensource.org/licenses/bsd-license.php
*/
namespace nodge\eauth\services\extended;
class TwitterOAuth1Service extends \nodge\eauth\services\TwitterOAuth1Service
{
protected function fetchAttributes()
{
$info = $this->makeSignedRequest('account/verify_credentials.json');
$this->attributes['id'] = $info['id'];
$this->attributes['name'] = $info['name'];
$this->attributes['url'] = 'http://twitter.com/account/redirect_by_id?id=' . $info['id_str'];
$this->attributes['username'] = $info['screen_name'];
$this->attributes['language'] = $info['lang'];
$this->attributes['timezone'] = timezone_name_from_abbr('', $info['utc_offset'], date('I'));
$this->attributes['photo'] = $info['profile_image_url'];
return true;
}
/**
* Returns the error array.
*
* @param array $response
* @return array the error array with 2 keys: code and message. Should be null if no errors.
*/
protected function fetchResponseError($response)
{
if (isset($response['errors'])) {
$first = reset($response['errors']);
return [
'code' => $first['code'],
'message' => $first['message'],
];
}
return null;
}
}