- Модуль: socialservices
- Путь к файлу: ~/bitrix/modules/socialservices/classes/general/google.php
- Класс: CGoogleOAuthInterface
- Вызов: CGoogleOAuthInterface::GetCurrentUserFriends
public function GetCurrentUserFriends($limit, &$next)
{
if($this->access_token === false)
return false;
$http = new HttpClient();
$http->setHeader('GData-Version', '3.0');
$http->setHeader('Authorization', 'Bearer '.$this->access_token);
$url = static::FRIENDS_URL.'?';
$limit = (int)$limit;
$next = (int)$next;
if ($limit > 0)
{
$url .= '&max-results='.$limit;
}
if ($next > 0)
{
$url .= '&start-index='.$next;
}
$result = $http->get($url);
if (!defined("BX_UTF"))
{
$result = BitrixMainTextEncoding::convertEncoding($string, $charset_in, $charset_out)($result, "utf-8", LANG_CHARSET);
}
if((int)$http->getStatus() === 200)
{
$obXml = new CDataXML();
if($obXml->loadString($result))
{
$tree = $obXml->getTree();
$total = $tree->elementsByName("totalResults");
$total = (int)$total[0]->textContent();
$limitNode = $tree->elementsByName("itemsPerPage");
$next += (int)$limitNode[0]->textContent();
if($next >= $total)
{
$next = '__finish__';
}
$arFriends = array();
$arEntries = $tree->elementsByName('entry');
foreach($arEntries as $entry)
{
$arEntry = array();
$entryChildren = $entry->children();
foreach ($entryChildren as $child)
{
$tag = $child->name();
switch($tag)
{
case 'category':
case 'updated':
case 'edited';
break;
case 'name':
$arEntry[$tag] = array();
foreach($child->children() as $subChild)
{
$arEntry[$tag][$subChild->name()] = $subChild->textContent();
}
break;
case 'email':
if($child->getAttribute('primary') == 'true')
{
$arEntry[$tag] = $child->getAttribute('address');
}
break;
default:
$tagContent = $tag == 'link'
? $child->getAttribute('href')
: $child->textContent();
if($child->getAttribute('rel'))
{
if(!isset($arEntry[$tag]))
{
$arEntry[$tag] = array();
}
$arEntry[$tag][preg_replace("/^[^#]*#/", "", $child->getAttribute('rel'))] = $tagContent;
}
elseif(isset($arEntry[$tag]))
{
if(!is_array($arEntry[$tag][0]) || !isset($arEntry[$tag][0]))
{
$arEntry[$tag] = array($arEntry[$tag], $tagContent);
}
else
{
$arEntry[$tag][] = $tagContent;
}
}
else
{
$arEntry[$tag] = $tagContent;
}
}
}
if($arEntry['email'])
{
$arFriends[] = $arEntry;
}
}
return $arFriends;
}
}
return false;
}