private function prepareUserAndKey() { $this->test_data->user = Factory_User::create(); $this->test_data->api_key = Factory_ApiKey::create(array('uid' => $this->test_data->user->uid)); }
use OAuthException; $_SERVER['SERVER_NAME'] = isset($argv[1]) ? $argv[1] : die('SERVER_NAME argument missing' . PHP_EOL); require_once preg_replace('~/bin/(.*)\\.php~', '/lib/init.php', __FILE__); $q = "SELECT DISTINCT connection_id as id FROM publications p LEFT JOIN connections c ON c.external_id=p.connection_id WHERE c.service= 'User_Facebook'"; $connectionIds = $db->getObjectIds($q); $deleteCount = 0; foreach ($connectionIds as $connectionId) { $postIds = array(); $quotedPostIds = array(); $q = $db->buildQuery("SELECT external_id, object_id FROM publications WHERE connection_id=%d", $connectionId); $rs = $db->query($q); while ($o = $db->fetchObject($rs)) { $postIds[] = $connectionId . "_" . $o->external_id; $quotedPostIds[] = "'" . $connectionId . "_" . $o->external_id . "'"; } $apiUser = Factory_User::getInstance('User_Facebook', $connectionId); // Split postIds into smaller sets, FQL has a maximum length and a failure results in OAuthException: An unknown error has occurred $postIds = array_chunk($postIds, 100); $quotedPostIds = array_chunk($quotedPostIds, 100); foreach ($quotedPostIds as $setId => $postIdSet) { // Get stream $qPostIds = $db->implode($postIdSet); $q = "SELECT post_id, created_time FROM stream WHERE source_id = {$connectionId} AND post_id IN ({$qPostIds})"; $rs = $apiUser->api()->api('fql', 'get', array('q' => $q)); if (!$rs || !isset($rs['data'])) { continue; } $fbPostIds = array(); $minCreatedTime = null; foreach ($rs['data'] as $post) { $fbPostIds[] = $post['post_id'];
<?php use OAuthException; $_SERVER['SERVER_NAME'] = isset($argv[1]) ? $argv[1] : die('SERVER_NAME argument missing' . PHP_EOL); require_once preg_replace('~/bin/(.*)\\.php~', '/lib/init.php', __FILE__); $q = "SELECT DISTINCT connection_id as id FROM publications p LEFT JOIN connections c ON c.external_id=p.connection_id WHERE c.service='User_Twitter'"; $connectionIds = $db->getObjectIds($q); $deleteCount = 0; foreach ($connectionIds as $connectionId) { $lastTweet = null; $tweetIds = array(); $q = $db->buildQuery("SELECT external_id FROM publications WHERE connection_id=%d", $connectionId); $rs = $db->query($q); while ($o = $db->fetchObject($rs)) { $tweetIds[] = $o->external_id; } $apiUser = Factory_User::getInstance('User_Twitter', $connectionId); $rs = $apiUser->api()->get('account/rate_limit_status'); if (!$rs) { echo "No valid result from Twitter (connection {$connectionId})."; continue; } if ($rs->remaining_hits < 10) { $resetTime = $rs->reset_time_in_seconds; $wait = $resetTime - time(); echo "Less than 10 query hits remaining (" . $rs->remaining_hits . "), replenishes in {$wait}s." . PHP_EOL; continue; } $getMore = true; $maxId = 0; while ($getMore) { $arrParams = array('count' => 800, 'include_rts' => true, 'replies' => 'all');
private function prepareUserAndApiKey() { $this->test_data->user = Factory_User::create(); $this->test_data->api_key = Factory_ApiKey::create(array('uid' => $this->test_data->user->uid)); $this->test_data->headers = array("X-MATECAT-KEY: {$this->test_data->api_key->api_key}", "X-MATECAT-SECRET: {$this->test_data->api_key->api_secret}"); }