Esempio n. 1
0
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
}
Esempio n. 2
0
 public function testFetchInstanceUserInfo()
 {
     $fbc = new FacebookCrawler($this->instance, $this->fb);
     $session_key = 'adsfasdfasdfasdf';
     $fbc->fetchInstanceUserInfo($this->instance->network_user_id, $session_key);
     $this->assertTrue(isset($fbc->owner_object));
     $this->assertEqual($fbc->owner_object->user_id, 606837591);
 }
Esempio n. 3
0
 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__);
     }
 }
Esempio n. 4
0
 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 testFetchInstanceUserInfo()
 {
     $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken');
     $fbc->fetchInstanceUserInfo();
     $user_dao = new UserMySQLDAO();
     $user = $user_dao->getUserByName('Gina Trapani', 'facebook');
     $this->assertTrue(isset($user));
     $this->assertEqual($user->username, 'Gina Trapani');
     $this->assertEqual($user->full_name, 'Gina Trapani');
     $this->assertEqual($user->user_id, 606837591);
     $this->assertEqual($user->location, "San Diego, California");
     $this->assertEqual($user->description, 'Blogger and software developer. Project Director at Expert Labs. Co-host of This Week in Google.');
     $this->assertEqual($user->url, '');
 }
Esempio n. 6
0
 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
 }
 function testFetchInstanceUserInfo()
 {
     $fbc = new FacebookCrawler($this->instance, $this->logger, $this->fb, $this->db);
     $session_key = 'f8c16f44b43083fc2545a46d-606837591';
     $fbc->fetchInstanceUserInfo($this->instance->network_user_id, $session_key);
 }
Esempio n. 8
0
 function testFetchInstanceUserInfo()
 {
     $fbc = new FacebookCrawler($this->instance, $this->fb);
     $session_key = 'adsfasdfasdfasdf';
     $fbc->fetchInstanceUserInfo($this->instance->network_user_id, $session_key);
 }