示例#1
0
 public function testFetchUserPagesThatUserIsaFanOf()
 {
     $this->instance->network_user_id = '606837591';
     $fbc = new FacebookCrawler($this->instance, $this->fb);
     $session_key = 'asdfasdfasdfa';
     $pages = $fbc->fetchPagesUserIsFanOf($this->instance->network_user_id, $session_key);
     //        print_r($pages);
     $this->assertEqual(sizeof($pages), 43);
     $this->assertEqual($pages[29]['page_id'], '63811549237');
     $this->assertEqual($pages[29]['name'], 'The White House');
     $this->assertEqual($pages[29]['page_url'], 'http://www.facebook.com/WhiteHouse');
     $this->assertEqual($pages[15]['page_id'], '110253595679921');
     $this->assertEqual($pages[15]['name'], 'The Shawshank Redemption (1994)');
     $this->assertEqual($pages[15]['page_url'], 'http://www.imdb.com/title/tt0111161/');
 }
 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();
 }
 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();
 }