You are here

function socialfeed_instagram_posts in Social Feed 7.2

Same name and namespace in other branches
  1. 7 socialfeed.module \socialfeed_instagram_posts()

Uses socialfeed_instagram_posts() for fetching instagram pictures.

Return value

array Returns Instagram Feed.

Throws

\Exception

File

./socialfeed.block.inc, line 411
File include for Social Feed module.

Code

function socialfeed_instagram_posts() {
  $i = 0;
  $images = $pic = [];
  $instagram_post_link = variable_get('socialfeed_instagram_post_link');
  $access_token = variable_get('socialfeed_instagram_access_token');
  $limit = variable_get('socialfeed_instagram_picture_count');
  $url = SOCIALFEED_INSTAGRAM_GRAPH_URL . '&limit=' . $limit . '&access_token=' . $access_token;
  $request = drupal_http_request($url);
  $status = strtoupper($request->status_message);
  if ($status == 'OK') {
    if (isset($access_token) && !empty($access_token)) {
      $json_response = drupal_json_decode($request->data);
      foreach ($json_response['data'] as $key => $response_data) {
        if ($instagram_post_link == 1) {
          $images[$key]['media_url'] = $response_data['media_url'];
          $images[$key]['permalink'] = $response_data['permalink'];
        }
        $pic[] = $response_data['media_url'];
        $i++;
        if ($i == $limit) {
          break;
        }
      }
      return $images;
    }
    else {
      drupal_set_message(t('The access_token provided is invalid.'), 'error');
    }
  }
  else {
    drupal_set_message(t('Please provide your Instagram credentials <a href="@instagram">here</a>.', [
      '@instagram' => url('admin/config/services/socialfeed/instagram'),
    ]), 'warning');
  }
}