You are here

function socialfeed_foursquare in Social Feed 6

Retrieves Data from Foursquare.

2 calls to socialfeed_foursquare()
socialfeed_cron in ./socialfeed.module
Implements hook_cron().
socialfeed_settings_form_submit in ./socialfeed.module
Implements form_submit().

File

./socialfeed.module, line 540
Module for fetching data from Facebook, Twitter, Youtube, and Foursquare. This module provides block content retrieved from a

Code

function socialfeed_foursquare() {
  $foursquare_access_token = variable_get('socialfeed_foursquare_access_token', FALSE);
  $thedata = drupal_http_request('https://api.foursquare.com/v2/users/self/checkins?oauth_token=' . $foursquare_access_token . '', array(), 'GET', NULL, 1);
  $theuserdata = drupal_http_request('https://api.foursquare.com/v2/users/self?oauth_token=' . $foursquare_access_token . '', array(), 'GET', NULL, 1);
  if ($thedata->status_message == 'OK' && $theuserdata->status_message == 'OK') {
    $fq_object = json_decode(str_replace("\\u2019", "'", $thedata->data));
    $fq_userobject = json_decode(str_replace("\\u2019", "'", $theuserdata->data));

    /**
     * Inserts Foursquare Data.
     */
    function socialfeed_foursquare_insert($table, $data, $user) {
      $query = "SELECT * FROM {socialfeed_post} WHERE id = '%s'";
      $sql = db_query_range($query, $data->id, 0, 1);
      while ($item = db_fetch_object($sql)) {
        $myterms[] = $item;
      }
      if (!$myterms) {
        if ($data->type == 'venueless') {
          $post = array();
          $post['id'] = $data->id;
          $post['venue'] = $data->location->name;
          $post['time'] = $data->createdAt;
          $post['shout'] = $data->shout;
          $post['post_type'] = 'foursquare';
          $post['name'] = $user->id;
          $post['title'] = $user->firstName;
        }
        else {
          $post = array();
          $post['id'] = $data->id;
          $post['venue'] = $data->venue->name;
          $post['city'] = $data->venue->location->city;
          $post['state'] = $data->venue->location->state;
          $post['time'] = $data->createdAt;
          $post['shout'] = $data->shout;
          $post['post_type'] = 'foursquare';
          $post['name'] = $user->id;
          $post['title'] = $user->firstName;
        }
        drupal_write_record('socialfeed_post', $post);
      }
    }
    if ($fq_object->response->checkins->items) {
      foreach ($fq_object->response->checkins->items as $object) {
        socialfeed_foursquare_insert("socialfeed_post", $object, $fq_userobject->response->user);
      }
    }
  }
}