1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
googleplus.php
См. документацию.
1<?php
3
4use \Bitrix\Main\Web\HttpClient;
5
7{
8 const ID = "GooglePlusOAuth";
9 const LOGIN_PREFIX = "GP_";
10
11 public function getEntityOAuth($code = false)
12 {
13 if(!$this->entityOAuth)
14 {
15 $this->entityOAuth = new CGooglePlusOAuthInterface();
16 }
17
18 return parent::getEntityOAuth($code);
19 }
20
21 public function GetSettings()
22 {
23 return array(
24 array("note"=>GetMessage("socserv_googleplus_note")),
25 );
26 }
27
28 public function getFriendsList($limit, &$next)
29 {
30 if($this->getEntityOAuth()->GetAccessToken() !== false)
31 {
32 $res = $this->getEntityOAuth()->getCurrentUserFriends($limit, $next);
33
34 foreach($res["items"] as $key => $contact)
35 {
36 $contact["uid"] = $contact["id"];
37
38 if(array_key_exists("name", $contact))
39 {
40 $contact["first_name"] = $contact["name"]["givenName"];
41 $contact["last_name"] = $contact["name"]["familyName"];
42 }
43 else
44 {
45 list($contact["first_name"], $contact["last_name"]) = explode(" ", $contact["displayName"], 2);
46 }
47
48 if(array_key_exists("image", $contact))
49 {
50 $contact["picture"] = preg_replace("/\?.*$/", "", $contact["image"]["url"]);
51 }
52
53 $res["items"][$key] = $contact;
54 }
55
56 return $res["items"];
57 }
58
59 return false;
60 }
61
62 public function getProfileUrl($uid)
63 {
64 return "https://plus.google.com/".$uid;
65 }
66}
67
69{
70 const SERVICE_ID = "GooglePlusOAuth";
71
72 const PROFILE_URL = 'https://www.googleapis.com/plus/v1/people/me';
73 const FRIENDS_URL = 'https://www.googleapis.com/plus/v1/people/me/people/visible';
74
75 const FRIENDS_FIELDS = 'items(displayName,emails,gender,id,image,name,nickname),nextPageToken,title,totalItems';
76
77 protected $standardScope = array(
78 'https://www.googleapis.com/auth/plus.login',
79 'https://www.googleapis.com/auth/plus.me',
80 );
81
82 public function getCurrentUser()
83 {
84 return $this->query(static::PROFILE_URL);
85 }
86
87 public function getCurrentUserFriends($limit, &$next)
88 {
89 $url = static::FRIENDS_URL.'?';//'fields='.urlencode(static::FRIENDS_FIELDS);
90
91 $limit = intval($limit);
92 if($limit > 0)
93 {
94 $url .= '&maxResults='.$limit;
95 }
96
97 if($next)
98 {
99 $url .= '&pageToken='.$next;
100 }
101
102 $result = $this->query($url);
103
104 $next = $result['nextPageToken'];
105 if(!$next)
106 {
107 $next = '__finish__';
108 }
109
110 return $result;
111 }
112
113 protected function query($url)
114 {
115 if($this->access_token === false)
116 return false;
117
118 $http = new HttpClient();
119 $http->setHeader("authorization", "Bearer ".$this->access_token);
120 $result = $http->get($url);
121
122 $result = CUtil::JsObjectToPhp($result);
123
124 return $result;
125 }
126}
const PROFILE_URL
Определения googleplus.php:72
const FRIENDS_URL
Определения googleplus.php:73
const SERVICE_ID
Определения googleplus.php:70
query($url)
Определения googleplus.php:113
getCurrentUserFriends($limit, &$next)
Определения googleplus.php:87
const FRIENDS_FIELDS
Определения googleplus.php:75
getCurrentUser()
Определения googleplus.php:82
Определения google.php:11
const ID
Определения googleplus.php:8
getProfileUrl($uid)
Определения googleplus.php:62
GetSettings()
Определения googleplus.php:21
getEntityOAuth($code=false)
Определения googleplus.php:11
getFriendsList($limit, &$next)
Определения googleplus.php:28
const LOGIN_PREFIX
Определения googleplus.php:9
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$uid
Определения hot_keys_act.php:8
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if(empty($signedUserToken)) $key
Определения quickway.php:257
$url
Определения iframe.php:7