You are here

function drupagram_fetch_recent_items in Drupagram 7

Same name and namespace in other branches
  1. 6 drupagram.inc \drupagram_fetch_recent_items()

Fetches a user's recent items.

1 call to drupagram_fetch_recent_items()
drupagram_cron in ./drupagram.module
Implements hook_cron().

File

./drupagram.inc, line 204
Instagram API functions

Code

function drupagram_fetch_recent_items($id) {
  $params = array();
  $account = drupagram_account_load($id);
  $min_id = db_query("SELECT MAX(drupagram_id) FROM {drupagram} WHERE username = :username", array(
    ':username' => $account->username,
  ))
    ->fetchField();
  $params['!min_id'] = (int) $min_id;
  $params['count'] = 6;
  $drupagram = drupagram_connect($account);
  $items = $drupagram
    ->user_recent($id);
  if (empty($items)) {
    return;
  }
  foreach ($items as $media) {
    drupagram_media_save($media);
  }
  if (count($items) > 0) {

    // drupagram_account_save($items[0]->user);
  }
  db_update('drupagram_account')
    ->fields(array(
    'last_refresh' => REQUEST_TIME,
  ))
    ->condition('drupagram_id', $account->id)
    ->execute();
}