protected function processPageActions($fb_user) { $messages = array("error" => '', "success" => '', "info" => ''); //authorize user if (isset($_GET["session"])) { $session_data = json_decode(str_replace("\\", "", $_GET["session"])); if (!isset($fb_user) && !isset($fb_user['name'])) { $user = FacebookGraphAPIAccessor::apiRequest('/me', $session_data->access_token); $fb_username = $user->name; } else { $fb_username = $fb_user['name']; } $messages['success'] = $this->saveAccessToken($session_data->uid, $session_data->access_token, $fb_username); } //insert pages if (isset($_GET["action"]) && $_GET["action"] == "add page" && isset($_GET["facebook_page_id"]) && isset($_GET["viewer_id"]) && isset($_GET["owner_id"]) && isset($_GET["instance_id"])) { //get access token $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $tokens = $oid->getOAuthTokens($_GET["instance_id"]); $access_token = $tokens['oauth_access_token']; $page_data = FacebookGraphAPIAccessor::apiRequest('/' . $_GET["facebook_page_id"], $access_token); $messages = self::insertPage($page_data->id, $_GET["viewer_id"], $_GET["instance_id"], $page_data->name, $page_data->picture, $messages); } return $messages; }
/** * Process actions based on $_GET parameters. Authorize FB user or add FB page. * @param arr $options Facebook plugin options * @param Facebook $facebook Facebook object */ protected function processPageActions($options, Facebook $facebook) { //authorize user if (isset($_GET["code"]) && isset($_GET["state"])) { //validate state to avoid CSRF attacks if ($_GET["state"] == SessionCache::get('facebook_auth_csrf')) { //Prepare API request //First, prep redirect URI $redirect_uri = urlencode(Utils::getApplicationURL() . 'account/?p=facebook'); //Build API request URL $api_req = 'https://graph.facebook.com/oauth/access_token?client_id=' . $options['facebook_app_id']->option_value . '&client_secret=' . $options['facebook_api_secret']->option_value . '&redirect_uri=' . $redirect_uri . '&state=' . SessionCache::get('facebook_auth_csrf') . '&code=' . $_GET["code"]; $access_token_response = FacebookGraphAPIAccessor::rawApiRequest($api_req, false); parse_str($access_token_response); if (isset($access_token)) { /** * Swap in short-term token for long-lived token as per * https://developers.facebook.com/docs/facebook-login/access-tokens/#extending */ $api_req = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=' . $options['facebook_app_id']->option_value . '&client_secret=' . $options['facebook_api_secret']->option_value . '&fb_exchange_token=' . $access_token; $access_token_response = FacebookGraphAPIAccessor::rawApiRequest($api_req, false); parse_str($access_token_response); $facebook->setAccessToken($access_token); $fb_user_profile = $facebook->api('/me'); $fb_username = $fb_user_profile['name']; $fb_user_id = $fb_user_profile['id']; if (empty($fb_username)) { $error = 'Sorry, ThinkUp does not support business accounts.'; $this->addErrorMessage($error, 'authorization'); } else { $this->addSuccessMessage($this->saveAccessToken($fb_user_id, $access_token, $fb_username), 'authorization'); } } else { $error_msg = "Problem authorizing your Facebook account! Please correct your plugin settings."; $error_object = json_decode($access_token_response); if (isset($error_object) && isset($error_object->error->type) && isset($error_object->error->message)) { $error_msg = $error_msg . "<br>Facebook says: \"" . $error_object->error->type . ": " . $error_object->error->message . "\""; } else { $error_msg = $error_msg . "<br>Facebook's response: \"" . $access_token_response . "\""; } $this->addErrorMessage($error_msg, 'authorization', true); } } else { $this->addErrorMessage("Could not authenticate Facebook account due to invalid CSRF token.", 'authorization'); } } //insert pages if (isset($_GET["action"]) && $_GET["action"] == "add page" && isset($_GET["facebook_page_id"]) && isset($_GET["viewer_id"]) && isset($_GET["owner_id"]) && isset($_GET["instance_id"])) { //get access token $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $tokens = $oid->getOAuthTokens($_GET["instance_id"]); $access_token = $tokens['oauth_access_token']; $page_data = FacebookGraphAPIAccessor::apiRequest('/' . $_GET["facebook_page_id"], $access_token, "id,name,picture"); self::insertPage($page_data->id, $_GET["viewer_id"], $_GET["instance_id"], $page_data->name, $page_data->picture->data->url); } }
/** * Take a list of likes from a page or a post, run through pagination and add a count member to the object. * @param object $likes Likes Object structure from Facebook API * @return object */ private function normalizeLikes($likes) { $output = (object) array('count' => 0, 'data' => array()); // Just in case we get an object with the legacy layout if (!isset($likes->data)) { if (is_int($likes)) { $output->count = $likes; } elseif (is_object($likes) && isset($likes->count) && is_int($likes->count)) { $output->count = $likes->count; } return $output; } while ($likes !== null) { foreach ($likes->data as $like) { $output->data[] = $like; $output->count++; } if (!empty($likes->paging->next)) { $next_url = $likes->paging->next; //DEBUG //$this->logger->logInfo("Next likes url ".$next_url, __METHOD__.','.__LINE__); $likes = FacebookGraphAPIAccessor::apiRequestFullURL($next_url, $this->access_token); } else { $likes = null; } } return $output; }
/** * Process actions based on $_GET parameters. Authorize FB user or add FB page. * @param arr $options Facebook plugin options */ protected function processPageActions($options) { //authorize user if (isset($_GET["code"]) && isset($_GET["state"])) { //validate state to avoid CSRF attacks if ($_GET["state"] == SessionCache::get('facebook_auth_csrf')) { //Prepare API request //First, prep redirect URI $redirect_uri = Utils::getApplicationURL() . 'account/?p=facebook'; //Build API request URL $api_req = 'oauth/access_token'; $api_req_params = array('client_id' => $options['facebook_app_id']->option_value, 'client_secret' => $options['facebook_api_secret']->option_value, 'redirect_uri' => $redirect_uri, 'state' => SessionCache::get('facebook_auth_csrf'), 'code' => $_GET["code"]); $access_token_response = FacebookGraphAPIAccessor::apiRequest($api_req, null, $api_req_params, null); //DEBUG // Logger::getInstance()->logInfo("Access token response: " // .Utils::varDumpToString($access_token_response), __METHOD__.','.__LINE__); if (isset($access_token_response->error)) { $this->addErrorMessage("There was a problem. Facebook says: " . $access_token_response->error->message . " Please try again.", 'user_add'); $logger->logInfo("Added error message ", __METHOD__ . ',' . __LINE__); return; } $access_token = $access_token_response->access_token; if (isset($access_token)) { /** * Swap in short-term token for long-lived token as per * https://developers.facebook.com/docs/facebook-login/access-tokens/#extending */ $api_req = 'oauth/access_token'; $api_req_params = array('grant_type' => 'fb_exchange_token', 'client_id' => $options['facebook_app_id']->option_value, 'client_secret' => $options['facebook_api_secret']->option_value, 'fb_exchange_token' => $access_token); $access_token_response = FacebookGraphAPIAccessor::apiRequest($api_req, null, $api_req_params); // DEBUG // Logger::getInstance()->logInfo("Exchanged access token response: " // .Utils::varDumpToString($access_token_response), __METHOD__.','.__LINE__); $access_token = $access_token_response->access_token; $fb_user_profile = FacebookGraphAPIAccessor::apiRequest('me', $access_token, 'name,id'); //DEBUG // Logger::getInstance()->logInfo("FB user profile: ".Utils::varDumpToString($fb_user_profile), // __METHOD__.','.__LINE__); if (isset($fb_user_profile->error)) { $error_msg = "Problem authorizing your Facebook account!"; $error_object = $access_token_response; if (isset($error_object) && isset($error_object->error->type) && isset($error_object->error->message)) { $error_msg = $error_msg . "<br>Facebook says: \"" . $error_object->error->type . ": " . $error_object->error->message . "\""; } else { $error_msg = $error_msg . "<br>Facebook's response: \"" . $access_token_response . "\""; } $this->addErrorMessage($error_msg, 'user_add', true); } else { $fb_username = isset($fb_user_profile->name) ? $fb_user_profile->name : ''; $fb_user_id = isset($fb_user_profile->id) ? $fb_user_profile->id : ''; if (empty($fb_username)) { $error = 'Sorry, ThinkUp does not support business accounts.'; $this->addErrorMessage($error, 'user_add'); } else { $this->saveAccessToken($fb_user_id, $access_token, $fb_username); } } } else { $error_msg = "Problem authorizing your Facebook account! Please correct your plugin settings."; $error_object = $access_token_response; if (isset($error_object) && isset($error_object->error->type) && isset($error_object->error->message)) { $error_msg = $error_msg . "<br>Facebook says: \"" . $error_object->error->type . ": " . $error_object->error->message . "\""; } else { $error_msg = $error_msg . "<br>Facebook's response: \"" . $access_token_response . "\""; } $this->addErrorMessage($error_msg, 'user_add', true); } } else { $this->addErrorMessage("Could not authenticate Facebook account due to invalid CSRF token.", 'user_add'); } } }
private function storeFriends() { if ($this->instance->network != 'facebook') { return; } //Retrieve friends via the Facebook API $user_id = $this->instance->network_user_id; $access_token = $this->access_token; $network = $user_id == $this->instance->network_user_id ? $this->instance->network : 'facebook'; $friends = FacebookGraphAPIAccessor::apiRequest('/' . $user_id . '/friends', $access_token); if (isset($friends->data)) { //store relationships in follows table $follows_dao = DAOFactory::getDAO('FollowDAO'); $follower_count_dao = DAOFactory::getDAO('FollowerCountDAO'); $user_dao = DAOFactory::getDAO('UserDAO'); foreach ($friends->data as $friend) { $follower_id = $friend->id; if ($follows_dao->followExists($user_id, $follower_id, $network)) { // follow relationship already exists $follows_dao->update($user_id, $follower_id, $network); } else { // follow relationship does not exist yet $follows_dao->insert($user_id, $follower_id, $network); } //and users in users table. $follower_details = FacebookGraphAPIAccessor::apiRequest('/' . $follower_id, $this->access_token); $follower_details->network = $network; $follower = $this->parseUserDetails($follower_details); $follower_object = new User($follower); $user_dao->updateUser($follower_object); } //totals in follower_count table $follower_count_dao->insert($user_id, $network, count($friends->data)); } }
/** * Take a list of likes from a page or a post, run through pagination and add a count member to the object. * @param object $likes Likes Object structure from Facebook API * @return object */ private function normalizeLikes($likes) { $output = (object) array('count' => 0, 'data' => array()); // Just in case we get an object with the legacy layout if (!isset($likes->data)) { if (is_int($likes)) { $output->count = $likes; } elseif (is_object($likes) && isset($likes->count) && is_int($likes->count)) { $output->count = $likes->count; } return $output; } while ($likes !== null) { foreach ($likes->data as $like) { $output->data[] = $like; $output->count++; } if (!empty($likes->paging->next)) { $next_url = $likes->paging->next . '&access_token=' . $this->access_token; $likes = FacebookGraphAPIAccessor::rawApiRequest($next_url); } else { $likes = null; } } return $output; }
/** * Process actions based on $_GET parameters. Authorize FB user or add FB page. * @param arr $options Facebook plugin options * @param Facebook $facebook Facebook object */ protected function processPageActions($options, Facebook $facebook) { //authorize user if (isset($_GET["code"]) && isset($_GET["state"])) { //validate state to avoid CSRF attacks if ($_GET["state"] == SessionCache::get('facebook_auth_csrf')) { //Prepare API request //First, prep redirect URI $config = Config::getInstance(); $site_root_path = $config->getValue('site_root_path'); $redirect_uri = urlencode(sprintf('%s://%s%s%s', !empty($_SERVER['HTTPS']) ? 'https' : 'http', empty($_SERVER['SERVER_NAME']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'], $site_root_path, 'account/?p=facebook')); //Build API request URL $api_req = 'https://graph.facebook.com/oauth/access_token?client_id=' . $options['facebook_app_id']->option_value . '&client_secret=' . $options['facebook_api_secret']->option_value . '&redirect_uri=' . $redirect_uri . '&state=' . SessionCache::get('facebook_auth_csrf') . '&code=' . $_GET["code"]; $access_token_response = FacebookGraphAPIAccessor::rawApiRequest($api_req, false); parse_str($access_token_response); if (isset($access_token)) { $facebook->setAccessToken($access_token); $fb_user_profile = $facebook->api('/me'); $fb_username = $fb_user_profile['name']; $fb_user_id = $fb_user_profile['id']; $this->addSuccessMessage($this->saveAccessToken($fb_user_id, $access_token, $fb_username), 'authorization'); } else { $error_msg = "Problem authorizing your Facebook account! Please correct your plugin settings."; $error_object = json_decode($access_token_response); if (isset($error_object) && isset($error_object->error->type) && isset($error_object->error->message)) { $error_msg = $error_msg . "<br>Facebook says: \"" . $error_object->error->type . ": " . $error_object->error->message . "\""; } else { $error_msg = $error_msg . "<br>Facebook's response: \"" . $access_token_response . "\""; } $this->addErrorMessage($error_msg, 'authorization'); } } else { $this->addErrorMessage("Could not authenticate Facebook account due to invalid CSRF token.", 'authorization'); } } //insert pages if (isset($_GET["action"]) && $_GET["action"] == "add page" && isset($_GET["facebook_page_id"]) && isset($_GET["viewer_id"]) && isset($_GET["owner_id"]) && isset($_GET["instance_id"])) { //get access token $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $tokens = $oid->getOAuthTokens($_GET["instance_id"]); $access_token = $tokens['oauth_access_token']; $page_data = FacebookGraphAPIAccessor::apiRequest('/' . $_GET["facebook_page_id"], $access_token); self::insertPage($page_data->id, $_GET["viewer_id"], $_GET["instance_id"], $page_data->name, $page_data->picture); } }
/** * Convert parsed JSON of a profile or page's posts into ThinkUp posts and users * @param Object $stream * @param str $source The network for the post; by default 'facebook' */ private function parseStream($stream, $network) { $thinkup_posts = array(); $thinkup_users = array(); $profile = null; foreach ($stream->data as $p) { $post_id = explode("_", $p->id); $post_id = $post_id[1]; if ($profile == null) { $profile = $this->fetchUserInfo($p->from->id, $network, 'Post stream'); } //assume profile comments are private and page posts are public $is_protected = $network == 'facebook' ? 1 : 0; $ttp = array("post_id" => $post_id, "author_username" => $profile->username, "author_fullname" => $profile->username, "author_avatar" => $profile->avatar, "author_user_id" => $profile->user_id, "post_text" => isset($p->message) ? $p->message : '', "pub_date" => $p->created_time, "in_reply_to_user_id" => '', "in_reply_to_post_id" => '', "source" => '', 'network' => $network, 'is_protected' => $is_protected); array_push($thinkup_posts, $ttp); if (isset($p->comments)) { $comments_captured = 0; if (isset($p->comments->data)) { $post_comments = $p->comments->data; $post_comments_count = isset($post_comments) ? sizeof($post_comments) : 0; if (is_array($post_comments) && sizeof($post_comments) > 0) { foreach ($post_comments as $c) { if (isset($c->from)) { $comment_id = explode("_", $c->id); $comment_id = $comment_id[2]; //Get posts $ttp = array("post_id" => $comment_id, "author_username" => $c->from->name, "author_fullname" => $c->from->name, "author_avatar" => 'https://graph.facebook.com/' . $c->from->id . '/picture', "author_user_id" => $c->from->id, "post_text" => $c->message, "pub_date" => $c->created_time, "in_reply_to_user_id" => $profile->user_id, "in_reply_to_post_id" => $post_id, "source" => '', 'network' => $network, 'is_protected' => $is_protected); array_push($thinkup_posts, $ttp); //Get users $ttu = array("user_name" => $c->from->name, "full_name" => $c->from->name, "user_id" => $c->from->id, "avatar" => 'https://graph.facebook.com/' . $c->id . '/picture', "location" => '', "description" => '', "url" => '', "is_protected" => 'true', "follower_count" => 0, "post_count" => 0, "joined" => '', "found_in" => "Comments", "network" => 'facebook'); //Users are always set to network=facebook array_push($thinkup_users, $ttu); $comments_captured = $comments_captured + 1; } } } } // collapsed comment thread if (isset($p->comments->count) && $p->comments->count > $comments_captured) { $comments_stream = FacebookGraphAPIAccessor::apiRequest('/' . $p->from->id . '_' . $post_id . '/comments', $this->access_token); if (isset($comments_stream) && is_array($comments_stream->data)) { foreach ($comments_stream->data as $c) { if (isset($c->from)) { $comment_id = explode("_", $c->id); $comment_id = $comment_id[2]; //Get posts $ttp = array("post_id" => $comment_id, "author_username" => $c->from->name, "author_fullname" => $c->from->name, "author_avatar" => 'https://graph.facebook.com/' . $c->from->id . '/picture', "author_user_id" => $c->from->id, "post_text" => $c->message, "pub_date" => $c->created_time, "in_reply_to_user_id" => $profile->user_id, "in_reply_to_post_id" => $post_id, "source" => '', 'network' => $network, 'is_protected' => $is_protected); array_push($thinkup_posts, $ttp); //Get users $ttu = array("user_name" => $c->from->name, "full_name" => $c->from->name, "user_id" => $c->from->id, "avatar" => 'https://graph.facebook.com/' . $c->id . '/picture', "location" => '', "description" => '', "url" => '', "is_protected" => 'true', "follower_count" => 0, "post_count" => 0, "joined" => '', "found_in" => "Comments", "network" => 'facebook'); //Users are always set to network=facebook array_push($thinkup_users, $ttu); } } } } } } return array("posts" => $thinkup_posts, "users" => $thinkup_users); }
/** * Convert parsed JSON of a profile or page's posts into ThinkUp posts and users * @param Object $stream * @param str $source The network for the post; by default 'facebook' */ private function processStream($stream, $network) { $thinkup_posts = array(); $total_added_posts = 0; $thinkup_users = array(); $total_added_users = 0; $thinkup_links = array(); $total_links_added = 0; $thinkup_likes = array(); $total_added_likes = 0; $profile = null; $post_dao = DAOFactory::getDAO('PostDAO'); $must_process_likes = true; $must_process_comments = true; foreach ($stream->data as $p) { $post_id = explode("_", $p->id); $post_id = $post_id[1]; if ($profile == null) { $profile = $this->fetchUserInfo($p->from->id, $network, 'Post stream'); } //assume profile comments are private and page posts are public $is_protected = $network == 'facebook' ? 1 : 0; //get likes count $likes_count = 0; if (isset($p->likes)) { if (is_int($p->likes)) { $likes_count = $p->likes; } elseif (isset($p->likes->count) && is_int($p->likes->count)) { $likes_count = $p->likes->count; } } //Figure out if we have to process likes and comments $post_in_storage = $post_dao->getPost($post_id, $network); if (isset($post_in_storage)) { if ($post_in_storage->favlike_count_cache >= $likes_count) { $must_process_likes = false; $this->logger->logInfo("Already have " . $likes_count . " likes for post ID " . $post_id . "; Skipping like processing this crawler run", __METHOD__ . ',' . __LINE__); } if (isset($p->comments->count)) { if ($post_in_storage->reply_count_cache >= $p->comments->count) { $must_process_comments = false; $this->logger->logInfo("Already have " . $p->comments->count . " comments for post ID " . $post_id . "; Skipping comments processing", __METHOD__ . ',' . __LINE__); } } } if (isset($profile) && !isset($post_in_storage)) { $posts_to_process = array("post_id" => $post_id, "author_username" => $profile->username, "author_fullname" => $profile->username, "author_avatar" => $profile->avatar, "author_user_id" => $p->from->id, "post_text" => isset($p->message) ? $p->message : '', "pub_date" => $p->created_time, "favlike_count_cache" => $likes_count, "in_reply_to_user_id" => '', "in_reply_to_post_id" => '', "source" => '', 'network' => $network, 'is_protected' => $is_protected, 'location' => $profile->location); array_push($thinkup_posts, $posts_to_process); $total_added_posts = $total_added_posts + $this->storePostsAndAuthors($thinkup_posts, "Owner stream"); //free up memory $thinkup_posts = array(); if (isset($p->source) || isset($p->link)) { // there's a link to store $link_url = isset($p->source) ? $p->source : $p->link; $link = new Link(array("url" => $link_url, "expanded_url" => $link_url, "image_src" => isset($p->picture) ? $p->picture : '', "caption" => isset($p->caption) ? $p->caption : '', "description" => isset($p->description) ? $p->description : '', "title" => isset($p->name) ? $p->name : '', "network" => $network, "post_id" => $post_id)); array_push($thinkup_links, $link); } $total_links_addded = $total_links_added + $this->storeLinks($thinkup_links); if ($total_links_added > 0) { $this->logger->logUserSuccess("Collected {$total_links_added} new links", __METHOD__ . ',' . __LINE__); } //free up memory $thinkup_links = array(); } if ($must_process_comments) { if (isset($p->comments)) { $comments_captured = 0; if (isset($p->comments->data)) { $post_comments = $p->comments->data; $post_comments_count = isset($post_comments) ? sizeof($post_comments) : 0; if (is_array($post_comments) && sizeof($post_comments) > 0) { foreach ($post_comments as $c) { if (isset($c->from)) { $comment_id = explode("_", $c->id); $comment_id = $comment_id[2]; //Get posts $posts_to_process = array("post_id" => $comment_id, "author_username" => $c->from->name, "author_fullname" => $c->from->name, "author_avatar" => 'https://graph.facebook.com/' . $c->from->id . '/picture', "author_user_id" => $c->from->id, "post_text" => $c->message, "pub_date" => $c->created_time, "in_reply_to_user_id" => $profile->user_id, "in_reply_to_post_id" => $post_id, "source" => '', 'network' => $network, 'is_protected' => $is_protected, 'location' => ''); array_push($thinkup_posts, $posts_to_process); $comments_captured = $comments_captured + 1; } } } } $total_added_posts = $total_added_posts + $this->storePostsAndAuthors($thinkup_posts, "Post stream comments"); //free up memory $thinkup_posts = array(); // collapsed comment thread if (isset($p->comments->count) && $p->comments->count > $comments_captured) { $api_call = 'https://graph.facebook.com/' . $p->from->id . '_' . $post_id . '/comments?access_token=' . $this->access_token; do { $comments_stream = FacebookGraphAPIAccessor::rawApiRequest($api_call); if (isset($comments_stream) && is_array($comments_stream->data)) { foreach ($comments_stream->data as $c) { if (isset($c->from)) { $comment_id = explode("_", $c->id); $comment_id = $comment_id[sizeof($comment_id) - 1]; //Get posts $posts_to_process = array("post_id" => $comment_id, "author_username" => $c->from->name, "author_fullname" => $c->from->name, "author_avatar" => 'https://graph.facebook.com/' . $c->from->id . '/picture', "author_user_id" => $c->from->id, "post_text" => $c->message, "pub_date" => $c->created_time, "in_reply_to_user_id" => $profile->user_id, "in_reply_to_post_id" => $post_id, "source" => '', 'network' => $network, 'is_protected' => $is_protected, 'location' => ''); array_push($thinkup_posts, $posts_to_process); } } $total_added_posts = $total_added_posts + $this->storePostsAndAuthors($thinkup_posts, "Posts stream comments collapsed"); //free up memory $thinkup_posts = array(); if (isset($comments_stream->paging->next)) { $api_call = str_replace('\\u00257C', '|', $comments_stream->paging->next); } } else { // no comments (pun intended) break; } } while (isset($comments_stream->paging->next)); } } } //process "likes" if ($must_process_likes) { if (isset($p->likes)) { $likes_captured = 0; if (isset($p->likes->data)) { $post_likes = $p->likes->data; $post_likes_count = isset($post_likes) ? sizeof($post_likes) : 0; if (is_array($post_likes) && sizeof($post_likes) > 0) { foreach ($post_likes as $l) { if (isset($l->name) && isset($l->id)) { //Get users $ttu = array("user_name" => $l->name, "full_name" => $l->name, "user_id" => $l->id, "avatar" => 'https://graph.facebook.com/' . $l->id . '/picture', "location" => '', "description" => '', "url" => '', "is_protected" => 1, "follower_count" => 0, "post_count" => 0, "joined" => '', "found_in" => "Likes", "network" => 'facebook'); //Users are always set to network=facebook array_push($thinkup_users, $ttu); $fav_to_add = array("favoriter_id" => $l->id, "network" => $network, "author_user_id" => $profile->user_id, "post_id" => $post_id); array_push($thinkup_likes, $fav_to_add); $likes_captured = $likes_captured + 1; } } } } $total_added_users = $total_added_users + $this->storeUsers($thinkup_users, "Likes"); $total_added_likes = $total_added_likes + $this->storeLikes($thinkup_likes); //free up memory $thinkup_users = array(); $thinkup_likes = array(); // collapsed likes if (isset($p->likes->count) && $p->likes->count > $likes_captured) { $api_call = 'https://graph.facebook.com/' . $p->from->id . '_' . $post_id . '/likes?access_token=' . $this->access_token; do { $likes_stream = FacebookGraphAPIAccessor::rawApiRequest($api_call); if (isset($likes_stream) && is_array($likes_stream->data)) { foreach ($likes_stream->data as $l) { if (isset($l->name) && isset($l->id)) { //Get users $ttu = array("user_name" => $l->name, "full_name" => $l->name, "user_id" => $l->id, "avatar" => 'https://graph.facebook.com/' . $l->id . '/picture', "location" => '', "description" => '', "url" => '', "is_protected" => 1, "follower_count" => 0, "post_count" => 0, "joined" => '', "found_in" => "Likes", "network" => 'facebook'); //Users are always set to network=facebook array_push($thinkup_users, $ttu); $fav_to_add = array("favoriter_id" => $l->id, "network" => $network, "author_user_id" => $p->from->id, "post_id" => $post_id); array_push($thinkup_likes, $fav_to_add); $likes_captured = $likes_captured + 1; } } $total_added_users = $total_added_users + $this->storeUsers($thinkup_users, "Likes"); $total_added_likes = $total_added_likes + $this->storeLikes($thinkup_likes); //free up memory $thinkup_users = array(); $thinkup_likes = array(); if (isset($likes_stream->paging->next)) { $api_call = str_replace('\\u00257C', '|', $likes_stream->paging->next); } } else { // no likes break; } } while (isset($likes_stream->paging->next)); } } //free up memory $thinkup_users = array(); $thinkup_likes = array(); } } if ($total_added_posts > 0) { $this->logger->logUserSuccess("Collected {$total_added_posts} posts", __METHOD__ . ',' . __LINE__); } else { $this->logger->logUserInfo("No new posts found.", __METHOD__ . ',' . __LINE__); } if ($total_added_users > 0) { $this->logger->logUserSuccess("Collected {$total_added_users} users", __METHOD__ . ',' . __LINE__); } else { $this->logger->logUserInfo("No new users found.", __METHOD__ . ',' . __LINE__); } if ($total_added_likes > 0) { $this->logger->logUserSuccess("Collected {$total_added_likes} likes", __METHOD__ . ',' . __LINE__); } else { $this->logger->logUserInfo("No new likes found.", __METHOD__ . ',' . __LINE__); } }