public function testFetchUserPostsAndReplies()
 {
     $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken');
     $fbc->fetchUserPostsAndReplies($this->instance->network_user_id);
     $pd = new PostMySQLDAO();
     $post = $pd->getPost('158944054123704', 'facebook');
     $this->assertEqual($post->post_text, 'that movie made me want to build things');
     $this->assertEqual($post->reply_count_cache, 0);
     $post = $pd->getPost('153956564638648', 'facebook');
     $this->assertEqual($post->post_text, 'Britney Glee episode tonight. I may explode into a million pieces, splattered all over my living room walls.');
     $this->assertEqual($post->reply_count_cache, 19);
     $post = $pd->getPost('1546020', 'facebook');
     $this->assertPattern('/not the target demographic/', $post->post_text);
     $this->assertEqual($post->reply_count_cache, 0);
     $this->assertEqual($post->in_reply_to_post_id, '153956564638648');
     $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->avatar, 'https://graph.facebook.com/606837591/picture');
     $user = $user_dao->getUserByName('Mitch Wagner', 'facebook');
     $this->assertTrue(isset($user));
     $this->assertEqual($user->user_id, 697015835);
     $this->assertEqual($user->avatar, 'https://graph.facebook.com/697015835/picture');
 }
Exemplo n.º 2
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
}
Exemplo n.º 3
0
 public function testFetchUserStreamWithTwoPostsAndOneComment()
 {
     $this->instance->network_user_id = '6068375911';
     $fbc = new FacebookCrawler($this->instance, $this->fb);
     $session_key = 'adfasdfasdfasdf';
     $fbc->fetchUserPostsAndReplies($this->instance->network_user_id, $session_key);
     $pd = DAOFactory::getDAO('PostDAO');
     $p = $pd->getPost('108956622464235', 'facebook');
     $this->assertTrue($p->reply_count_cache == 1);
     $p = $pd->getPost('107266209295210', 'facebook');
     $this->assertTrue($p->reply_count_cache == 0);
 }
Exemplo 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);
         $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__);
     }
 }
Exemplo n.º 5
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
 }
 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);
 }
Exemplo n.º 7
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
 }
Exemplo n.º 8
0
    public function testFetchUserPostsAndReplies() {
        $fbc = new FacebookCrawler($this->instance, 'fauxaccesstoken');

        $fbc->fetchUserPostsAndReplies($this->instance->network_user_id);

        $pd = new PostMySQLDAO();
        $post = $pd->getPost('158944054123704', 'facebook');
        $this->assertEqual($post->post_text, 'that movie made me want to build things');
        $this->assertEqual($post->reply_count_cache, 0);

        $post = $pd->getPost('153956564638648', 'facebook');
        $this->assertEqual($post->post_text,
        'Britney Glee episode tonight. I may explode into a million pieces, splattered all over my living room walls.');
        $this->assertEqual($post->reply_count_cache, 19);

        $post = $pd->getPost('1546020', 'facebook');
        $this->assertPattern('/not the target demographic/', $post->post_text);
        $this->assertEqual($post->reply_count_cache, 0);
        $this->assertEqual($post->in_reply_to_post_id, '153956564638648');
    }