You are here

function socialfeed_facebook in Social Feed 6

Retrieves Data from Facebook.

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

File

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

Code

function socialfeed_facebook() {
  $profile_id = variable_get('socialfeed_facebook_profile_id', FALSE);

  // App Info, needed for Auth.
  $app_id = variable_get('socialfeed_facebook_app_id', FALSE);
  $app_secret = variable_get('socialfeed_facebook_app_secret', FALSE);

  // Retrieve auth token.
  $authtoken = drupal_http_request("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={$app_id}&client_secret={$app_secret}", array(), 'GET', NULL, 1);
  if ($authtoken->status_message == 'OK') {
    $data = drupal_http_request("https://graph.facebook.com/{$profile_id}/feed?{$authtoken->data}", array(), 'GET', NULL, 1);
    $data_con = $data->data;
    $result = json_decode(str_replace("\\u2019", "'", $data_con));

    /**
     * Inserts Facebook Data.
     */
    function socialfeed_facebook_insert($table, $data) {
      $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) {
        $post = array();
        $post['id'] = $data->id;
        $post['time'] = strtotime($data->created_time);
        $post['message'] = $data->message;
        $post['fbtype'] = $data->type;
        $post['picture'] = $data->picture;
        $post['link'] = $data->link;
        $post['name'] = $data->from->name;
        $post['description'] = $data->description;
        $post['post_type'] = 'facebook';
        drupal_write_record('socialfeed_post', $post);
      }
    }
    if ($result->data) {
      foreach ($result->data as $object) {
        $profileid = explode('_', $object->id);
        if ($object->from->id == $profileid[0]) {
          socialfeed_facebook_insert("socialfeed_post", $object);
        }
      }
    }
  }
}