|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SocialConnect project |
|
4
|
|
|
* @author: Patsura Dmitry https://github.com/ovr <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace SocialConnect\OAuth1\Provider; |
|
8
|
|
|
|
|
9
|
|
|
use SocialConnect\Provider\AccessTokenInterface; |
|
10
|
|
|
use SocialConnect\Provider\Exception\InvalidResponse; |
|
11
|
|
|
use SocialConnect\Common\Entity\User; |
|
12
|
|
|
use SocialConnect\Common\Http\Client\Client; |
|
13
|
|
|
use SocialConnect\Common\Hydrator\ObjectMap; |
|
14
|
|
|
|
|
15
|
|
|
class Twitter extends \SocialConnect\OAuth1\AbstractProvider |
|
16
|
|
|
{ |
|
17
|
|
|
public function getBaseUri() |
|
18
|
|
|
{ |
|
19
|
|
|
return 'https://api.twitter.com/1.1/'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function getAuthorizeUri() |
|
23
|
|
|
{ |
|
24
|
|
|
return 'https://api.twitter.com/oauth/authenticate'; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getRequestTokenUri() |
|
28
|
|
|
{ |
|
29
|
|
|
return 'https://api.twitter.com/oauth/request_token'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getRequestTokenAccessUri() |
|
33
|
|
|
{ |
|
34
|
|
|
return 'https://api.twitter.com/oauth/access_token'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getName() |
|
38
|
|
|
{ |
|
39
|
|
|
return 'twitter'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getIdentity(AccessTokenInterface $accessToken) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->consumerToken = $accessToken; |
|
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
$parameters = $this->requestTokenParams; |
|
50
|
|
|
$parameters['user_id'] = $accessToken->getUserId(); |
|
51
|
|
|
|
|
52
|
|
|
$response = $this->oauthRequest( |
|
53
|
|
|
$this->getBaseUri() . 'users/lookup.json', |
|
54
|
|
|
Client::GET, |
|
55
|
|
|
$parameters, |
|
56
|
|
|
$this->requestTokenHeaders |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
if (!$response->isSuccess()) { |
|
60
|
|
|
throw new InvalidResponse( |
|
61
|
|
|
'API response with error code', |
|
62
|
|
|
$response |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$result = $response->json(); |
|
67
|
|
|
if (!$result) { |
|
68
|
|
|
throw new InvalidResponse( |
|
69
|
|
|
'API response is not a valid JSON object', |
|
70
|
|
|
$response->getBody() |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$hydrator = new ObjectMap( |
|
75
|
|
|
[ |
|
76
|
|
|
'id' => 'id', |
|
77
|
|
|
'name' => 'fullname', |
|
78
|
|
|
'screen_name' => 'username' |
|
79
|
|
|
] |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
return $hydrator->hydrate(new User(), $result[0]); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..