public function updateData($import = false) { // Get service propertie $config = Zend_Registry::get("configuration"); $pages = $import ? 50 : 1; $count = $import ? 200 : 50; // Get application properties $app_properties = new Properties(array(Stuffpress_Db_Properties::KEY => Zend_Registry::get("shard"))); // Get twitter user properties $username = $this->getProperty('username'); $uid = $this->getProperty('uid', 0); if (!$username) { throw new Stuffpress_Exception("Update failed, connector not properly configured"); } // Get twitter consumer tokens and user secrets $consumer_key = $config->twitter->consumer_key; $consumer_secret = $config->twitter->consumer_secret; $oauth_token = $app_properties->getProperty('twitter_oauth_token'); $oauth_token_secret = $app_properties->getProperty('twitter_oauth_token_secret'); if (!$consumer_key || !$consumer_secret || !$oauth_token || !$oauth_token_secret) { throw new Stuffpress_Exception("Missing twitter credentials. Please configure your twitter account in the <a href='/admin/sns/'>Configure -> Social Networks</a> section."); } // Fetch the data from twitter $result = array(); $connection = new TwitterOAuth_Client($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret); $connection->host = "https://api.twitter.com/1.1/"; $max_id = false; $params = array('screen_name' => $username, 'count' => $count); for ($page = 1; $page <= $pages; $page++) { if ($max_id) { $params['max_id'] = $max_id; } $response = $connection->get('statuses/user_timeline', $params); if ($response && isset($response->errors) && count($response->errors) > 0) { throw new Stuffpress_Exception($response->errors[0]->message); } if (count($response) == 0) { break; } $max_id = $response[count($response) - 1]->id_str; $items = $this->processItems($response); if (count($items) == 0) { break; } $result = array_merge($result, $items); } // Mark as updated (could have been with errors) $this->markUpdated(); return $result; }