function facebook_crawl() { //TODO Crawl Facebook posts and comments and insert them into the database global $THINKTANK_CFG; global $db; global $conn; $logger = new Logger($THINKTANK_CFG['log_location']); $id = new InstanceDAO($db, $logger); $oid = new OwnerInstanceDAO($db, $logger); $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook'); foreach ($instances as $i) { $logger->setUsername($i->network_username); $tokens = $oid->getOAuthTokens($i->id); $session_key = $tokens['oauth_access_token']; $fb = new Facebook($THINKTANK_CFG['facebook_api_key'], $THINKTANK_CFG['facebook_api_secret']); $cfg = new Config($i->network_username, $i->network_user_id); $id->updateLastRun($i->id); $crawler = new FacebookCrawler($i, $logger, $fb, $db); $crawler->fetchInstanceUserInfo($i->network_user_id, $session_key); $crawler->fetchUserPostsAndReplies($i->network_user_id, $session_key); $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $fb); } $logger->close(); # Close logging }
public function crawl() { $logger = Logger::getInstance(); $config = Config::getInstance(); $instance_dao = DAOFactory::getDAO('FacebookInstanceDAO'); $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO'); $owner_dao = DAOFactory::getDAO('OwnerDAO'); $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('facebook', true); //get cached $max_crawl_time = isset($options['max_crawl_time']) ? $options['max_crawl_time']->option_value : 20; //convert to seconds $max_crawl_time = $max_crawl_time * 60; $current_owner = $owner_dao->getByEmail(Session::getLoggedInUser()); //crawl Facebook user profiles and pages $profiles = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'facebook'); $pages = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'facebook page'); $instances = array_merge($profiles, $pages); foreach ($instances as $instance) { $logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username); $logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__); $tokens = $owner_instance_dao->getOAuthTokens($instance->id); $access_token = $tokens['oauth_access_token']; $instance_dao->updateLastRun($instance->id); $facebook_crawler = new FacebookCrawler($instance, $access_token, $max_crawl_time); $dashboard_module_cacher = new DashboardModuleCacher($instance); try { $facebook_crawler->fetchPostsAndReplies(); } catch (APIOAuthException $e) { $logger->logUserError(get_class($e) . ": " . $e->getMessage(), __METHOD__ . ',' . __LINE__); //Don't send reauth email if it's app-level API rate limting //https://developers.facebook.com/docs/reference/ads-api/api-rate-limiting/#applimit if (strpos($e->getMessage(), 'Application request limit reached') === false && strpos($e->getMessage(), 'Please retry your request later.') === false) { //The access token is invalid, save in owner_instances table $owner_instance_dao->setAuthErrorByTokens($instance->id, $access_token, '', $e->getMessage()); //Send email alert //Get owner by auth tokens first, then send to that person $owner_email_to_notify = $owner_instance_dao->getOwnerEmailByInstanceTokens($instance->id, $access_token, ''); $email_attempt = $this->sendInvalidOAuthEmailAlert($owner_email_to_notify, $instance->network_username); if ($email_attempt) { $logger->logUserInfo('Sent reauth email to ' . $owner_email_to_notify, __METHOD__ . ',' . __LINE__); } else { $logger->logInfo('Didn\'t send reauth email to ' . $owner_email_to_notify, __METHOD__ . ',' . __LINE__); } } else { $logger->logInfo('Facebook API returned an error: ' . $e->getMessage() . ' Do nothing now and try again later', __METHOD__ . ',' . __LINE__); } } catch (Exception $e) { $logger->logUserError(get_class($e) . ": " . $e->getMessage(), __METHOD__ . ',' . __LINE__); } $dashboard_module_cacher->cacheDashboardModules(); $instance_dao->save($facebook_crawler->instance, 0, $logger); Reporter::reportVersion($instance); $logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__); } }
public function crawl() { $logger = Logger::getInstance(); $config = Config::getInstance(); $id = DAOFactory::getDAO('InstanceDAO'); $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $od = DAOFactory::getDAO('OwnerDAO'); $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('facebook', true); //get cached $current_owner = $od->getByEmail(Session::getLoggedInUser()); //crawl Facebook user profiles $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook'); foreach ($instances as $instance) { if (!$oid->doesOwnerHaveAccess($current_owner, $instance)) { // Owner doesn't have access to this instance; let's not crawl it. continue; } $logger->setUsername($instance->network_username); $tokens = $oid->getOAuthTokens($instance->id); $session_key = $tokens['oauth_access_token']; $fb = new Facebook($options['facebook_api_key']->option_value, $options['facebook_api_secret']->option_value); $id->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $fb); try { $crawler->fetchInstanceUserInfo($instance->network_user_id, $session_key); $crawler->fetchUserPostsAndReplies($instance->network_user_id, $session_key); } catch (Exception $e) { $logger->logStatus('PROFILE EXCEPTION: ' . $e->getMessage(), get_class($this)); } $id->save($crawler->instance, $crawler->owner_object->post_count, $logger); } //crawl Facebook pages $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook page'); foreach ($instances as $instance) { $logger->setUsername($instance->network_username); $tokens = $oid->getOAuthTokens($instance->id); $session_key = $tokens['oauth_access_token']; $fb = new Facebook($options['facebook_api_key']->option_value, $options['facebook_api_secret']->option_value); $id->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $fb); try { $crawler->fetchPagePostsAndReplies($instance->network_user_id, $instance->network_viewer_id, $session_key); } catch (Exception $e) { $logger->logStatus('PAGE EXCEPTION: ' . $e->getMessage(), get_class($this)); } $id->save($crawler->instance, 0, $logger); } $logger->close(); # Close logging }
public function crawl() { $logger = Logger::getInstance(); $config = Config::getInstance(); $id = DAOFactory::getDAO('InstanceDAO'); $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $od = DAOFactory::getDAO('OwnerDAO'); $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('facebook', true); //get cached $current_owner = $od->getByEmail(Session::getLoggedInUser()); //crawl Facebook user profiles $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook'); foreach ($instances as $instance) { if (!$oid->doesOwnerHaveAccess($current_owner, $instance)) { // Owner doesn't have access to this instance; let's not crawl it. continue; } $logger->setUsername($instance->network_username); $logger->logUserSuccess("Starting to collect data for " . $instance->network_username . " on Facebook.", __METHOD__ . ',' . __LINE__); $tokens = $oid->getOAuthTokens($instance->id); $access_token = $tokens['oauth_access_token']; $id->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $access_token); try { $crawler->fetchInstanceUserInfo(); $crawler->fetchUserPostsAndReplies($instance->network_user_id); } catch (Exception $e) { $logger->logUserError('PROFILE EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__); } $id->save($crawler->instance, 0, $logger); $logger->logUserSuccess("Finished collecting data for " . $instance->network_username . " on Facebook.", __METHOD__ . ',' . __LINE__); } //crawl Facebook pages $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook page'); foreach ($instances as $instance) { $logger->setUsername($instance->network_username); $logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s Facebook Page.", __METHOD__ . ',' . __LINE__); $tokens = $oid->getOAuthTokens($instance->id); $access_token = $tokens['oauth_access_token']; $id->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $access_token); try { $crawler->fetchPagePostsAndReplies($instance->network_user_id); } catch (Exception $e) { $logger->logUserError('PAGE EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__); } $id->save($crawler->instance, 0, $logger); $logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s Facebook Page.", __METHOD__ . ',' . __LINE__); } }
public function authControl() { $config = Config::getInstance(); $this->setViewTemplate($config->getValue('source_root_path') . 'webapp/plugins/facebook/view/facebook.account.index.tpl'); $status = self::processPageActions(); $this->addToView("info", $status["info"]); $this->addToView("error", $status["error"]); $this->addToView("success", $status["success"]); $logger = Logger::getInstance(); $user_pages = array(); $owner_instances = $this->id->getByOwnerAndNetwork($this->owner, 'facebook'); $api_key = $config->getValue('facebook_api_key'); $api_secret = $config->getValue('facebook_api_secret'); if (isset($api_key) && isset($api_secret)) { //echo "keys set: ".$api_key." ".$api_secret; $facebook = new Facebook($api_key, $api_secret); foreach ($owner_instances as $instance) { $crawler = new FacebookCrawler($instance, $facebook); $tokens = $this->oid->getOAuthTokens($instance->id); $session_key = $tokens['oauth_access_token']; if ($instance->network_user_id == $instance->network_viewer_id) { $pages = $crawler->fetchPagesUserIsFanOf($instance->network_user_id, $session_key); $keys = array_keys($pages); foreach ($keys as $key) { $pages[$key]["json"] = json_encode($pages[$key]); } $user_pages[$instance->network_user_id] = $pages; } } } else { echo "keys not set"; $this->addToView("error", "Please set your Facebook API key and secret in config.inc.php"); } $this->addToView('user_pages', $user_pages); $owner_instance_pages = $this->id->getByOwnerAndNetwork($this->owner, 'facebook page'); $this->addToView('owner_instance_pages', $owner_instance_pages); $fbconnect_link = '<a href="#" onclick="FB.Connect.requireSession(); return false;" ><img id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_long.gif" alt="Connect"/> </a>'; $this->addToView('fbconnect_link', $fbconnect_link); $this->addToView('owner_instances', $owner_instances); if (isset($api_key)) { $this->addToView('fb_api_key', $api_key); } return $this->generateView(); }
function testFetchUserStreamWithTwoPostsAndOneComment() { /* $this->assertTrue(unserialize('a:2:{s:5:"posts";a:2:{i:0;a:21:{s:7:"post_id";s:25:"606837591_108956622464235";s:9:"viewer_id";s:9:"606837591";s:9:"source_id";s:9:"606837591";s:4:"type";s:2:"46";s:6:"app_id";s:0:"";s:11:"attribution";s:0:"";s:8:"actor_id";s:9:"606837591";s:9:"target_id";s:0:"";s:7:"message";s:50:"The Pacific is really good. Can\'t wait for part 3.";s:10:"attachment";a:1:{s:11:"description";s:0:"";}s:8:"app_data";s:0:"";s:12:"action_links";s:0:"";s:8:"comments";a:4:{s:10:"can_remove";s:1:"1";s:8:"can_post";s:1:"1";s:5:"count";s:1:"0";s:12:"comment_list";s:0:"";}s:5:"likes";a:6:{s:4:"href";s:82:"http://www.facebook.com/social_graph.php?node_id=108956622464235&class=LikeManager";s:5:"count";s:1:"0";s:6:"sample";s:0:"";s:7:"friends";s:0:"";s:10:"user_likes";s:1:"0";s:8:"can_like";s:1:"1";}s:7:"privacy";a:6:{s:11:"description";s:12:"Only Friends";s:5:"value";s:11:"ALL_FRIENDS";s:7:"friends";s:0:"";s:8:"networks";s:0:"";s:5:"allow";s:0:"";s:4:"deny";s:0:"";}s:12:"updated_time";s:10:"1269488627";s:12:"created_time";s:10:"1269488627";s:10:"tagged_ids";s:0:"";s:9:"is_hidden";s:1:"0";s:10:"filter_key";s:34:"f8c16f44b43083fc2545a46d-606837591";s:9:"permalink";s:82:"http://www.facebook.com/profile.php?v=feed&story_fbid=108956622464235&id=606837591";}i:1;a:21:{s:7:"post_id";s:25:"606837591_107266209295210";s:9:"viewer_id";s:9:"606837591";s:9:"source_id";s:9:"606837591";s:4:"type";s:2:"46";s:6:"app_id";s:0:"";s:11:"attribution";s:0:"";s:8:"actor_id";s:9:"606837591";s:9:"target_id";s:0:"";s:7:"message";s:23:"SHAKE IT LIKE A POM-POM";s:10:"attachment";a:1:{s:11:"description";s:0:"";}s:8:"app_data";s:0:"";s:12:"action_links";s:0:"";s:8:"comments";a:4:{s:10:"can_remove";s:1:"1";s:8:"can_post";s:1:"1";s:5:"count";s:1:"0";s:12:"comment_list";s:0:"";}s:5:"likes";a:6:{s:4:"href";s:82:"http://www.facebook.com/social_graph.php?node_id=107266209295210&class=LikeManager";s:5:"count";s:1:"0";s:6:"sample";s:0:"";s:7:"friends";s:0:"";s:10:"user_likes";s:1:"0";s:8:"can_like";s:1:"1";}s:7:"privacy";a:6:{s:11:"description";s:12:"Only Friends";s:5:"value";s:11:"ALL_FRIENDS";s:7:"friends";s:0:"";s:8:"networks";s:0:"";s:5:"allow";s:0:"";s:4:"deny";s:0:"";}s:12:"updated_time";s:10:"1269411918";s:12:"created_time";s:10:"1269411918";s:10:"tagged_ids";s:0:"";s:9:"is_hidden";s:1:"0";s:10:"filter_key";s:34:"f8c16f44b43083fc2545a46d-606837591";s:9:"permalink";s:82:"http://www.facebook.com/profile.php?v=feed&story_fbid=107266209295210&id=606837591";}}s:8:"profiles";a:1:{i:0;a:5:{s:2:"id";s:9:"606837591";s:3:"url";s:0:"";s:4:"name";s:12:"Gina Trapani";s:10:"pic_square";s:60:"http://profile.ak.fbcdn.net/v222/1942/94/q606837591_9678.jpg";s:4:"type";s:4:"user";}}}')); $stream = unserialize('a:2:{s:5:"posts";a:2:{i:0;a:21:{s:7:"post_id";s:25:"606837591_108956622464235";s:9:"viewer_id";s:9:"606837591";s:9:"source_id";s:9:"606837591";s:4:"type";s:2:"46";s:6:"app_id";s:0:"";s:11:"attribution";s:0:"";s:8:"actor_id";s:9:"606837591";s:9:"target_id";s:0:"";s:7:"message";s:50:"The Pacific is really good. Can\'t wait for part 3.";s:10:"attachment";a:1:{s:11:"description";s:0:"";}s:8:"app_data";s:0:"";s:12:"action_links";s:0:"";s:8:"comments";a:4:{s:10:"can_remove";s:1:"1";s:8:"can_post";s:1:"1";s:5:"count";s:1:"0";s:12:"comment_list";s:0:"";}s:5:"likes";a:6:{s:4:"href";s:82:"http://www.facebook.com/social_graph.php?node_id=108956622464235&class=LikeManager";s:5:"count";s:1:"0";s:6:"sample";s:0:"";s:7:"friends";s:0:"";s:10:"user_likes";s:1:"0";s:8:"can_like";s:1:"1";}s:7:"privacy";a:6:{s:11:"description";s:12:"Only Friends";s:5:"value";s:11:"ALL_FRIENDS";s:7:"friends";s:0:"";s:8:"networks";s:0:"";s:5:"allow";s:0:"";s:4:"deny";s:0:"";}s:12:"updated_time";s:10:"1269488627";s:12:"created_time";s:10:"1269488627";s:10:"tagged_ids";s:0:"";s:9:"is_hidden";s:1:"0";s:10:"filter_key";s:34:"f8c16f44b43083fc2545a46d-606837591";s:9:"permalink";s:82:"http://www.facebook.com/profile.php?v=feed&story_fbid=108956622464235&id=606837591";}i:1;a:21:{s:7:"post_id";s:25:"606837591_107266209295210";s:9:"viewer_id";s:9:"606837591";s:9:"source_id";s:9:"606837591";s:4:"type";s:2:"46";s:6:"app_id";s:0:"";s:11:"attribution";s:0:"";s:8:"actor_id";s:9:"606837591";s:9:"target_id";s:0:"";s:7:"message";s:23:"SHAKE IT LIKE A POM-POM";s:10:"attachment";a:1:{s:11:"description";s:0:"";}s:8:"app_data";s:0:"";s:12:"action_links";s:0:"";s:8:"comments";a:4:{s:10:"can_remove";s:1:"1";s:8:"can_post";s:1:"1";s:5:"count";s:1:"0";s:12:"comment_list";s:0:"";}s:5:"likes";a:6:{s:4:"href";s:82:"http://www.facebook.com/social_graph.php?node_id=107266209295210&class=LikeManager";s:5:"count";s:1:"0";s:6:"sample";s:0:"";s:7:"friends";s:0:"";s:10:"user_likes";s:1:"0";s:8:"can_like";s:1:"1";}s:7:"privacy";a:6:{s:11:"description";s:12:"Only Friends";s:5:"value";s:11:"ALL_FRIENDS";s:7:"friends";s:0:"";s:8:"networks";s:0:"";s:5:"allow";s:0:"";s:4:"deny";s:0:"";}s:12:"updated_time";s:10:"1269411918";s:12:"created_time";s:10:"1269411918";s:10:"tagged_ids";s:0:"";s:9:"is_hidden";s:1:"0";s:10:"filter_key";s:34:"f8c16f44b43083fc2545a46d-606837591";s:9:"permalink";s:82:"http://www.facebook.com/profile.php?v=feed&story_fbid=107266209295210&id=606837591";}}s:8:"profiles";a:1:{i:0;a:5:{s:2:"id";s:9:"606837591";s:3:"url";s:0:"";s:4:"name";s:12:"Gina Trapani";s:10:"pic_square";s:60:"http://profile.ak.fbcdn.net/v222/1942/94/q606837591_9678.jpg";s:4:"type";s:4:"user";}}}'); $this->assertTrue(is_array($stream)); $this->assertTrue(is_array($stream["posts"])); //print_r($stream["posts"]); */ $this->instance->network_user_id = '6068375911'; $fbc = new FacebookCrawler($this->instance, $this->logger, $this->fb, $this->db); $session_key = 'f8c16f44b43083fc2545a46d-606837591'; $fbc->fetchUserPostsAndReplies($this->instance->network_user_id, $session_key); $pd = new PostDAO($this->db, $this->logger); $p = $pd->getPost('108956622464235'); $this->assertTrue($p->mention_count_cache == 1); $p = $pd->getPost('107266209295210'); $this->assertTrue($p->mention_count_cache == 0); }
public function crawl() { $logger = Logger::getInstance(); $config = Config::getInstance(); $instance_dao = DAOFactory::getDAO('InstanceDAO'); $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO'); $owner_dao = DAOFactory::getDAO('OwnerDAO'); $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('facebook', true); //get cached $max_crawl_time = isset($options['max_crawl_time']) ? $options['max_crawl_time']->option_value : 20; //convert to seconds $max_crawl_time = $max_crawl_time * 60; $current_owner = $owner_dao->getByEmail(Session::getLoggedInUser()); //crawl Facebook user profiles and pages $profiles = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'facebook'); $pages = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'facebook page'); $instances = array_merge($profiles, $pages); foreach ($instances as $instance) { $logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username); $logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__); $tokens = $owner_instance_dao->getOAuthTokens($instance->id); $access_token = $tokens['oauth_access_token']; $instance_dao->updateLastRun($instance->id); $facebook_crawler = new FacebookCrawler($instance, $access_token, $max_crawl_time); $dashboard_module_cacher = new DashboardModuleCacher($instance); try { $facebook_crawler->fetchPostsAndReplies(); } catch (APIOAuthException $e) { //The access token is invalid, save in owner_instances table $owner_instance_dao->setAuthError($current_owner->id, $instance->id, $e->getMessage()); //Send email alert $this->sendInvalidOAuthEmailAlert($current_owner->email, $instance->network_username); $logger->logUserError('EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__); } catch (Exception $e) { $logger->logUserError('EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__); } $dashboard_module_cacher->cacheDashboardModules(); $instance_dao->save($facebook_crawler->instance, 0, $logger); Reporter::reportVersion($instance); $logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__); } }
function analyze() { $crawler = new FacebookCrawler($this->search, $this->current_cookie); $results = $crawler->getTextBetweenTags('<div class="_5d-5">'); $i = 1; $this->response .= 'Results: ' . sizeof($results) . '<br>'; foreach ($results as $r) { $link = $crawler->extractLinkAmount('<a class="_8o _8s lfloat _ohe"', $i); $image = $crawler->extractImageAmount(' aria-hidden="true" tabindex="-1">', $i); $username = str_replace('https://www.facebook.com/', '', $link); $username = substr($username, 0, strpos($username, '?')); $this->response .= '<br>Name: <a href="' . $link . '">' . $r . '</a><br>'; $this->response .= 'Username: '******'<br>'; $this->response .= 'Profile Picture: <br>'; $this->response .= '<img src="' . $image . '" width="100" height="100"<br><br>'; $this->stack[$i - 1]['title'] = 'Name: ' . $r; $this->stack[$i - 1]['text'] = 'Username: '******'image_url'] = 'Username: '******'color'] = '#556FA3'; $i++; } }
public function crawl() { $logger = Logger::getInstance(); $config = Config::getInstance(); $instance_dao = DAOFactory::getDAO('InstanceDAO'); $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO'); $owner_dao = DAOFactory::getDAO('OwnerDAO'); $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('facebook', true); //get cached $max_crawl_time = isset($options['max_crawl_time']) ? $options['max_crawl_time']->option_value : 20; //convert to seconds $max_crawl_time = $max_crawl_time * 60; $current_owner = $owner_dao->getByEmail(Session::getLoggedInUser()); //crawl Facebook user profiles and pages $profiles = $instance_dao->getAllActiveInstancesStalestFirstByNetwork('facebook'); $pages = $instance_dao->getAllActiveInstancesStalestFirstByNetwork('facebook page'); $instances = array_merge($profiles, $pages); foreach ($instances as $instance) { if (!$owner_instance_dao->doesOwnerHaveAccessToInstance($current_owner, $instance)) { // Owner doesn't have access to this instance; let's not crawl it. continue; } $logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username); $logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__); $tokens = $owner_instance_dao->getOAuthTokens($instance->id); $access_token = $tokens['oauth_access_token']; $instance_dao->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $access_token, $max_crawl_time); try { $crawler->fetchPostsAndReplies(); } catch (Exception $e) { $logger->logUserError('EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__); } $instance_dao->save($crawler->instance, 0, $logger); $logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__); } }
public function crawl() { global $db; //TODO Remove when PDO port is complete global $conn; $logger = Logger::getInstance(); $config = Config::getInstance(); $id = DAOFactory::getDAO('InstanceDAO'); $oid = new OwnerInstanceDAO($db, $logger); //crawl Facebook user profiles $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook'); foreach ($instances as $instance) { $logger->setUsername($instance->network_username); $tokens = $oid->getOAuthTokens($instance->id); $session_key = $tokens['oauth_access_token']; $fb = new Facebook($config->getValue('facebook_api_key'), $config->getValue('facebook_api_secret')); $id->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $fb); $crawler->fetchInstanceUserInfo($instance->network_user_id, $session_key); $crawler->fetchUserPostsAndReplies($instance->network_user_id, $session_key); $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $fb); } //crawl Facebook pages $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook page'); foreach ($instances as $instance) { $logger->setUsername($instance->network_username); $tokens = $oid->getOAuthTokens($instance->id); $session_key = $tokens['oauth_access_token']; $fb = new Facebook($config->getValue('facebook_api_key'), $config->getValue('facebook_api_secret')); $id->updateLastRun($instance->id); $crawler = new FacebookCrawler($instance, $fb); $crawler->fetchPagePostsAndReplies($instance->network_user_id, $instance->network_viewer_id, $session_key); $id->save($crawler->instance, 0, $logger, $fb); } $logger->close(); # Close logging }
public function testPostReplyPaging() { $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken'); $fbc->fetchPostsAndReplies('133954286636768', true); $post_dao = new PostMySQLDAO(); $post = $post_dao->getPost('144568048938151', 'facebook page'); $this->assertEqual($post->reply_count_cache, 70); }
public function authControl() { $config = Config::getInstance(); Utils::defineConstants(); $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/facebook/view/facebook.account.index.tpl'); /** set option fields **/ // API Key text field $this->addPluginOption(self::FORM_TEXT_ELEMENT, array('name' => 'facebook_api_key', 'label' => 'Your Facebook API Key')); // add element $this->addPluginOptionHeader('facebook_api_key', 'Facebook Configuration'); // set a special required message $this->addPluginOptionRequiredMessage('facebook_api_key', 'The Facebook plugin requires a valid API Key.'); // Application Secret text field $this->addPluginOption(self::FORM_TEXT_ELEMENT, array('name' => 'facebook_api_secret', 'label' => 'Your Facebook Application Secret')); // add element // set a special required message $this->addPluginOptionRequiredMessage('facebook_api_secret', 'The Facebook plugin requires a valid Application Secret.'); $status = self::processPageActions(); $this->addToView("info", $status["info"]); $this->addToView("error", $status["error"]); $this->addToView("success", $status["success"]); $logger = Logger::getInstance(); $user_pages = array(); $owner_instances = $this->id->getByOwnerAndNetwork($this->owner, 'facebook'); $plugin_option_dao = DAOFactory::getDAO('PluginOptionDAO'); $options = $plugin_option_dao->getOptionsHash('facebook', true); //get cached if (isset($options['facebook_api_key']) && isset($options['facebook_api_secret'])) { $api_key = $options['facebook_api_key']->option_value; $api_secret = $options['facebook_api_secret']->option_value; //echo "keys set: ".$api_key." ".$api_secret; $facebook = new Facebook($api_key, $api_secret); foreach ($owner_instances as $instance) { $crawler = new FacebookCrawler($instance, $facebook); $tokens = $this->oid->getOAuthTokens($instance->id); $session_key = $tokens['oauth_access_token']; if ($instance->network_user_id == $instance->network_viewer_id) { $pages = $crawler->fetchPagesUserIsFanOf($instance->network_user_id, $session_key); if ($pages) { $keys = array_keys($pages); foreach ($keys as $key) { $pages[$key]["json"] = json_encode($pages[$key]); } $user_pages[$instance->network_user_id] = $pages; $this->addToView('user_pages', $user_pages); } } } } else { $this->addErrorMessage("Please set your Facebook API Key and Application Secret."); } $owner_instance_pages = $this->id->getByOwnerAndNetwork($this->owner, 'facebook page'); $this->addToView('owner_instance_pages', $owner_instance_pages); $fbconnect_link = '<a href="#" onclick="FB.Connect.requireSession(); return false;" > <img id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_light_medium_long.gif" alt="Connect"/> </a>'; $this->addToView('fbconnect_link', $fbconnect_link); $this->addToView('owner_instances', $owner_instances); if (isset($options['facebook_api_key'])) { $this->addToView('fb_api_key', $options['facebook_api_key']->option_value); } return $this->generateView(); }
function fetch_life_events() { $crawler = new FacebookCrawler($this->profile, $this->current_cookie); $pics = $crawler->getTextBetweenTags('<div class="uiScaledImageContainer" style="width:101px;height:101px;">'); $this->response .= '<br>Sample of Pictures: <br>'; $i = 0; foreach ($pics as $p) { $this->response .= $p; $i++; if ($i == 3) { break; } } }
public function testFetchPageStream() { $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken'); $fbc->fetchPagePostsAndReplies(7568536355); $pd = new PostMySQLDAO(); $post = $pd->getPost('437900891355', 'facebook page'); $this->assertEqual($post->post_text, 'Top 10 iOS Jailbreak Hacks'); $this->assertEqual($post->reply_count_cache, 8); //assert user network is set to Facebook, not Facebook Page $ud = new UserMySQLDAO(); $user = $ud->getUserByName('Matthew Fleisher', 'facebook'); $this->assertEqual($user->full_name, 'Matthew Fleisher'); $this->assertEqual($user->network, 'facebook'); $user = $ud->getUserByName('Matthew Fleisher', 'facebook page'); $this->assertEqual($user, null); }
public function testPaginatedPostLikes() { $fbc = new FacebookCrawler($this->profile5_instance, 'fauxaccesstoken', 10); $fbc->fetchPostsAndReplies('501771984', 'facebook'); $post_dao = new PostMySQLDAO(); $post = $post_dao->getPost('10151734003261985', 'facebook'); $this->assertEqual($post->favlike_count_cache, 27); }
public function testFetchPageStream() { $this->instance->network_user_id = '606837591'; $fbc = new FacebookCrawler($this->instance, $this->fb); $session_key = 'asdfasdfasdfadf'; $page_id = '63811549237'; $fbc->fetchPagePostsAndReplies($page_id, $this->instance->network_user_id, $session_key); $pd = DAOFactory::getDAO('PostDAO'); $p = $pd->getPost('125634574117714', 'facebook'); $this->assertEqual($p->post_text, "Thanks for checking out the West Wing Week, your guide to everything that's happening at " . "1600 Pennsylvania Ave."); }
public function testFetchPostsAndRepliesForPage() { $fbc = new FacebookCrawler($this->page1_instance, 'abc', 10); $fbc->fetchPostsAndReplies(); $post_dao = new PostMySQLDAO(); $post = $post_dao->getPost('10152714332426356', 'facebook page'); $this->assertEqual($post->post_text, 'Looks like a very serene place to work:'); $this->assertFalse($post->is_protected); $this->assertEqual($post->reply_count_cache, 4); //test link with image $this->assertEqual(sizeof($post->links), 1); $this->assertEqual($post->links[0]->url, 'http://lifehac.kr/Jg0mR3E'); $this->assertEqual($post->links[0]->expanded_url, ''); $this->assertEqual($post->links[0]->image_src, 'https://fbexternal-a.akamaihd.net/safe_image.php?d=AQDJyDKV3JDoU0-y&w=130&h=130&url=http%3A%2F%2' . 'Fi.kinja-img.com%2Fgawker-media%2Fimage%2Fupload%2Fs--G2ekOhHZ--%2Fgobnypf78nigkkl7cwpl.png&cfs=1'); $this->assertEqual($post->links[0]->description, 'Today’s featured workspace looks immaculate, with its pristine white walls, simple white desk, and ' . 'wood accents. Those skylights help too.'); //assert user network is set to Facebook, not Facebook Page $ud = new UserMySQLDAO(); $user = $ud->getUserByName('Gregory Robert Dumas', 'facebook'); $this->assertEqual($user->full_name, 'Gregory Robert Dumas'); $this->assertEqual($user->network, 'facebook'); $this->assertTrue($user->is_protected); $user = $ud->getUserByName('Matthew Fleisher', 'facebook page'); $this->assertEqual($user, null); $fav_dao = new FavoritePostMySQLDAO(); $favs = $fav_dao->getUsersWhoFavedPost('10152714332426356', 'facebook page'); $this->assertEqual($favs[0]['user_name'], 'Peter-Sarah Crofton'); $this->assertEqual($favs[0]['user_id'], '25913266'); // Test Facebook paging by confirming post on second "page" was captured $post = $post_dao->getPost('10152712264921356', 'facebook page'); $this->assertNotNull($post); $this->assertEqual($post->author_user_id, '7568536355'); }