You are here

function socialfeed_instagram_posts in Social Feed 7

Same name and namespace in other branches
  1. 7.2 socialfeed.block.inc \socialfeed_instagram_posts()

Uses socialfeed_instagram_posts() for fetching instagram pictures.

1 call to socialfeed_instagram_posts()
socialfeed_block_view in ./socialfeed.module
Implements hook_block_view().

File

./socialfeed.module, line 374
Provide Facebook, Twitter and Instagram.

Code

function socialfeed_instagram_posts() {
  $images = array();
  $i = 0;
  libraries_load('instagram');
  $instagram = new Instagram(array(
    'apiKey' => variable_get('socialfeed_instagram_api_key'),
    'apiSecret' => variable_get('socialfeed_instagram_api_secret'),
    'apiCallback' => variable_get('socialfeed_instagram_redirect_uri'),
  ));
  if (isset($instagram
    ->getUserMedia(variable_get('socialfeed_instagram_user_id'))->data) && !empty($instagram
    ->getUserMedia(variable_get('socialfeed_instagram_user_id'))->data)) {
    $instagram_objects = $instagram
      ->getUserMedia(variable_get('socialfeed_instagram_user_id'))->data;
    foreach ($instagram_objects as $instagram_object) {
      $resolution = variable_get('socialfeed_instagram_picture_resolution');
      $images[] = $instagram_object->images->{$resolution}->url;
      $i++;
      if ($i == variable_get('socialfeed_instagram_picture_count')) {
        break;
      }
    }
    return theme('socialfeed_instagram', array(
      'instagram_images' => $images,
    ));
  }
  elseif (empty($instagram
    ->getUserMedia(variable_get('socialfeed_instagram_user_id'))->data)) {
    drupal_set_message(t('Please provide valid User ID at the Instagram <a href="@configuration">configuration page</a>.', array(
      '@configuration' => 'admin/config/services/socialfeed/instagram',
    )), 'warning');
  }
  else {
    drupal_set_message(t('Please provide your credentials at the Instagram <a href="@configuration">configuration page</a>.', array(
      '@configuration' => 'admin/config/services/socialfeed/instagram',
    )), 'warning');
  }
}