-
Notifications
You must be signed in to change notification settings - Fork 0
/
OAuthOdnoklasniki.class.php
60 lines (51 loc) · 2.22 KB
/
OAuthOdnoklasniki.class.php
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
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Class for OAuth Odnoklasniki
* @see http://dev.odnoklassniki.ru/wiki/pages/viewpage.action?pageId=12878032
*
* @param string $clientId App id
* @param string $clientSecret Secret key
* @param string $applicationKey Application ID
* @param string $code Authorization code, received with user return the url
* @param string $host Url auth (request from this url, and response to this url)
*
*
* @return array $user Include next field:
*
* @return string uid Unique user id in Odnoklasniki
* @return string first_name First name
* @return string last_name Last name
* @return mixed birthday Birthday
* @return string gender User gender
* @return string pic_1 Small photo
* @return string pic_2 Big photo
*/
class OAuthOdnoklasniki {
public $clientId;
public $clientSecret;
public $applicationKey;
public $code;
public $host;
public function __construct($clientId, $clientSecret, $applicationKey, $code, $host) {
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
$this->applicationKey = $applicationKey;
$this->code = $code;
$this->host = $host;
}
public function getUserData() {
$curl = curl_init('http://api.odnoklassniki.ru/oauth/token.do');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'code=' . $this->code . '&redirect_uri=' . urlencode($this->host) . '&grant_type=authorization_code&client_id=' . $this->clientId . '&client_secret=' . $this->clientSecret);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$s = curl_exec($curl);
curl_close($curl);
$auth = json_decode($s, true);
$curl = curl_init('http://api.odnoklassniki.ru/fb.do?access_token=' . $auth['access_token'] . '&application_key=' . $this->applicationKey . '&method=users.getCurrentUser&sig=' . md5('application_key=' . $this->applicationKey . 'method=users.getCurrentUser' . md5($auth['access_token'] . $this->clientSecret)));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$s = curl_exec($curl);
curl_close($curl);
$user = json_decode($s, true);
return $user;
}
}