You are here

protected function SocialGoogleFormatter::getComments in Open Social 7

Get comments from activity ID.

Parameters

string $id: Activity ID.

Return value

array Array with comments.

1 call to SocialGoogleFormatter::getComments()
SocialGoogleFormatter::getData in includes/social_comments.google.inc

File

includes/social_comments.google.inc, line 98
Google class

Class

SocialGoogleFormatter
@file Google class

Code

protected function getComments($id) {
  $comments = array();
  $cache_key = 'social_comments:google:' . $id;
  if ($cache = cache_get($cache_key)) {
    $comments = $cache->data;
  }
  else {
    $query = array(
      'key' => $this->api_key,
    );
    $query = array_filter($query);
    $response_url = url('https://www.googleapis.com/plus/v1/activities/' . $id . '/comments', array(
      'query' => $query,
    ));
    $data = drupal_http_request($response_url);
    if ($data->code != 200) {
      watchdog('social_comments', $data->error, array(), WATCHDOG_WARNING);
      return FALSE;
    }
    $result = drupal_json_decode($data->data);
    if (!empty($result['items'])) {
      $comments = $result['items'];

      // Set data to cache.
      cache_set($cache_key, $comments, 'cache', $this->expire + REQUEST_TIME);
    }
  }
  return $comments;
}