Merge remote-tracking branch 'origin/1.1.x' into 1.1.x
This commit is contained in:
commit
2361fde21a
@ -242,8 +242,9 @@ class OAuthClient
|
||||
'ssl_verify_host' => false
|
||||
));
|
||||
|
||||
// Twitter is strict about accepting invalid "Expect" headers
|
||||
$request->setHeader('Expect', '');
|
||||
// Twitter was strict about accepting invalid "Expect" headers
|
||||
// between 2008ish and October 2012. Caused "417 Expectation failed"
|
||||
//$request->setHeader('Expect', '');
|
||||
|
||||
if (isset($params)) {
|
||||
$request->setMethod(HTTP_Request2::METHOD_POST);
|
||||
|
@ -204,6 +204,7 @@ class TwitterBridgePlugin extends Plugin
|
||||
return false;
|
||||
case 'TwitterOAuthClient':
|
||||
case 'TwitterQueueHandler':
|
||||
case 'TweetInQueueHandler':
|
||||
case 'TwitterImport':
|
||||
case 'JsonStreamReader':
|
||||
case 'TwitterStreamReader':
|
||||
|
@ -136,7 +136,8 @@ class TwitterStatusFetcher extends ParallelizingDaemon
|
||||
// a new connection if there isn't one already
|
||||
$conn = &$flink->getDatabaseConnection();
|
||||
|
||||
$this->getTimeline($flink);
|
||||
$this->getTimeline($flink, 'home_timeline');
|
||||
$this->getTimeline($flink, 'mentions_timeline');
|
||||
|
||||
$flink->last_friendsync = common_sql_now();
|
||||
$flink->update();
|
||||
@ -149,65 +150,68 @@ class TwitterStatusFetcher extends ParallelizingDaemon
|
||||
unset($_DB_DATAOBJECT['CONNECTIONS']);
|
||||
}
|
||||
|
||||
function getTimeline($flink)
|
||||
function getTimeline($flink, $timelineUri = 'home_timeline')
|
||||
{
|
||||
if (empty($flink)) {
|
||||
common_log(LOG_WARNING, $this->name() .
|
||||
common_log(LOG_ERR, $this->name() .
|
||||
" - Can't retrieve Foreign_link for foreign ID $fid");
|
||||
return;
|
||||
}
|
||||
|
||||
common_debug($this->name() . ' - Trying to get timeline for Twitter user ' .
|
||||
$flink->foreign_id);
|
||||
common_log(LOG_DEBUG, $this->name() . ' - Trying to get ' . $timelineUri .
|
||||
' timeline for Twitter user ' . $flink->foreign_id);
|
||||
|
||||
$client = null;
|
||||
|
||||
if (TwitterOAuthClient::isPackedToken($flink->credentials)) {
|
||||
$token = TwitterOAuthClient::unpackToken($flink->credentials);
|
||||
$client = new TwitterOAuthClient($token->key, $token->secret);
|
||||
common_debug($this->name() . ' - Grabbing friends timeline with OAuth.');
|
||||
common_log(LOG_DEBUG, $this->name() . ' - Grabbing ' . $timelineUri . ' timeline with OAuth.');
|
||||
} else {
|
||||
common_debug("Skipping friends timeline for $flink->foreign_id since not OAuth.");
|
||||
common_log(LOG_ERR, "Skipping " . $timelineUri . " timeline for " .
|
||||
$flink->foreign_id . " since not OAuth.");
|
||||
}
|
||||
|
||||
$timeline = null;
|
||||
|
||||
$lastId = Twitter_synch_status::getLastId($flink->foreign_id, 'home_timeline');
|
||||
$lastId = Twitter_synch_status::getLastId($flink->foreign_id, $timelineUri);
|
||||
|
||||
common_debug("Got lastId value '{$lastId}' for foreign id '{$flink->foreign_id}' and timeline 'home_timeline'");
|
||||
common_log(LOG_DEBUG, "Got lastId value '" . $lastId . "' for foreign id '" .
|
||||
$flink->foreign_id . "' and timeline '" . $timelineUri. "'");
|
||||
|
||||
try {
|
||||
$timeline = $client->statusesHomeTimeline($lastId);
|
||||
$timeline = $client->statusesTimeline($lastId, $timelineUri);
|
||||
} catch (Exception $e) {
|
||||
common_log(LOG_WARNING, $this->name() .
|
||||
' - Twitter client unable to get friends timeline for user ' .
|
||||
$flink->user_id . ' - code: ' .
|
||||
$e->getCode() . 'msg: ' . $e->getMessage());
|
||||
common_log(LOG_ERR, $this->name() .
|
||||
' - Unable to get ' . $timelineUri . ' timeline for user ' . $flink->user_id .
|
||||
' - code: ' . $e->getCode() . 'msg: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (empty($timeline)) {
|
||||
common_log(LOG_WARNING, $this->name() . " - Empty timeline.");
|
||||
common_log(LOG_WARNING, $this->name() . " - Empty '" . $timelineUri . "' timeline.");
|
||||
return;
|
||||
}
|
||||
|
||||
common_debug(LOG_INFO, $this->name() . ' - Retrieved ' . sizeof($timeline) . ' statuses from Twitter.');
|
||||
|
||||
$importer = new TwitterImport();
|
||||
|
||||
// Reverse to preserve order
|
||||
|
||||
foreach (array_reverse($timeline) as $status) {
|
||||
$notice = $importer->importStatus($status);
|
||||
|
||||
if (!empty($notice)) {
|
||||
Inbox::insertNotice($flink->user_id, $notice->id);
|
||||
}
|
||||
}
|
||||
common_log(LOG_INFO, $this->name() .
|
||||
' - Retrieved ' . sizeof($timeline) . ' statuses from ' . $timelineUri . ' timeline' .
|
||||
' - for user ' . $flink->user_id);
|
||||
|
||||
if (!empty($timeline)) {
|
||||
$qm = QueueManager::get();
|
||||
|
||||
// Reverse to preserve order
|
||||
foreach (array_reverse($timeline) as $status) {
|
||||
$data = array(
|
||||
'status' => $status,
|
||||
'for_user' => $flink->foreign_id,
|
||||
);
|
||||
$qm->enqueue($data, 'tweetin');
|
||||
}
|
||||
|
||||
$lastId = twitter_id($timeline[0]);
|
||||
Twitter_synch_status::setLastId($flink->foreign_id, 'home_timeline', $lastId);
|
||||
common_debug("Set lastId value '$lastId' for foreign id '{$flink->foreign_id}' and timeline 'home_timeline'");
|
||||
Twitter_synch_status::setLastId($flink->foreign_id, $timelineUri, $lastId);
|
||||
common_debug("Set lastId value '$lastId' for foreign id '{$flink->foreign_id}' and timeline '" .
|
||||
$timelineUri . "'");
|
||||
}
|
||||
|
||||
// Okay, record the time we synced with Twitter for posterity
|
||||
@ -233,5 +237,5 @@ if (have_option('d') || have_option('debug')) {
|
||||
$debug = true;
|
||||
}
|
||||
|
||||
$fetcher = new TwitterStatusFetcher($id, 60, 2, $debug);
|
||||
$fetcher = new TwitterStatusFetcher($id, POLL_INTERVAL, MAXCHILDREN, $debug);
|
||||
$fetcher->runOnce();
|
||||
|
@ -51,10 +51,14 @@ class TweetInQueueHandler extends QueueHandler
|
||||
$importer = new TwitterImport();
|
||||
$notice = $importer->importStatus($status);
|
||||
if ($notice) {
|
||||
$flink = Foreign_link::getByForeignID(TWITTER_SERVICE, $receiver);
|
||||
$flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE);
|
||||
if ($flink) {
|
||||
common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice ".
|
||||
$notice->id." to inbox ".$flink->user_id);
|
||||
// @fixme this should go through more regular channels?
|
||||
Inbox::insertNotice($flink->user_id, $notice->id);
|
||||
}else {
|
||||
common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user ".$receiver);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ class TwitterOAuthClient extends OAuthClient
|
||||
*/
|
||||
function verifyCredentials()
|
||||
{
|
||||
$url = 'https://api.twitter.com/1/account/verify_credentials.json';
|
||||
$url = 'https://api.twitter.com/1.1/account/verify_credentials.json';
|
||||
$response = $this->oAuthGet($url);
|
||||
$twitter_user = json_decode($response);
|
||||
return $twitter_user;
|
||||
@ -175,7 +175,7 @@ class TwitterOAuthClient extends OAuthClient
|
||||
*/
|
||||
function statusesUpdate($status, $params=array())
|
||||
{
|
||||
$url = 'https://api.twitter.com/1/statuses/update.json';
|
||||
$url = 'https://api.twitter.com/1.1/statuses/update.json';
|
||||
if (is_numeric($params)) {
|
||||
$params = array('in_reply_to_status_id' => intval($params));
|
||||
}
|
||||
@ -191,18 +191,20 @@ class TwitterOAuthClient extends OAuthClient
|
||||
* Calls Twitter's /statuses/home_timeline API method
|
||||
*
|
||||
* @param int $since_id show statuses after this id
|
||||
* @param string $timelineUri timeline to poll statuses from
|
||||
* @param int $max_id show statuses before this id
|
||||
* @param int $cnt number of statuses to show
|
||||
* @param int $page page number
|
||||
*
|
||||
* @return mixed an array of statuses
|
||||
*/
|
||||
function statusesHomeTimeline($since_id = null, $max_id = null,
|
||||
$cnt = null, $page = null)
|
||||
function statusesTimeline($since_id = null, $timelineUri = 'home_timeline',
|
||||
$max_id = null, $cnt = 200, $page = null)
|
||||
{
|
||||
$url = 'https://api.twitter.com/1/statuses/home_timeline.json';
|
||||
$url = 'https://api.twitter.com/1.1/statuses/'.$timelineUri.'.json';
|
||||
|
||||
$params = array('include_entities' => 'true');
|
||||
$params = array('include_entities' => 'true',
|
||||
'include_rts' => 'true');
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$params['since_id'] = $since_id;
|
||||
@ -235,7 +237,7 @@ class TwitterOAuthClient extends OAuthClient
|
||||
function statusesFriends($id = null, $user_id = null, $screen_name = null,
|
||||
$page = null)
|
||||
{
|
||||
$url = "https://api.twitter.com/1/statuses/friends.json";
|
||||
$url = "https://api.twitter.com/1.1/friends/list.json";
|
||||
|
||||
$params = array();
|
||||
|
||||
@ -273,7 +275,7 @@ class TwitterOAuthClient extends OAuthClient
|
||||
function friendsIds($id = null, $user_id = null, $screen_name = null,
|
||||
$page = null)
|
||||
{
|
||||
$url = "https://api.twitter.com/1/friends/ids.json";
|
||||
$url = "https://api.twitter.com/1.1/friends/ids.json";
|
||||
|
||||
$params = array();
|
||||
|
||||
@ -308,7 +310,7 @@ class TwitterOAuthClient extends OAuthClient
|
||||
|
||||
function statusesRetweet($id)
|
||||
{
|
||||
$url = "http://api.twitter.com/1/statuses/retweet/$id.json";
|
||||
$url = "http://api.twitter.com/1.1/statuses/retweet/$id.json";
|
||||
$response = $this->oAuthPost($url);
|
||||
$status = json_decode($response);
|
||||
return $status;
|
||||
@ -324,8 +326,10 @@ class TwitterOAuthClient extends OAuthClient
|
||||
|
||||
function favoritesCreate($id)
|
||||
{
|
||||
$url = "http://api.twitter.com/1/favorites/create/$id.json";
|
||||
$response = $this->oAuthPost($url);
|
||||
$url = "http://api.twitter.com/1.1/favorites/create.json";
|
||||
$params=array();
|
||||
$params['id'] = $id;
|
||||
$response = $this->oAuthPost($url, $params);
|
||||
$status = json_decode($response);
|
||||
return $status;
|
||||
}
|
||||
@ -340,8 +344,10 @@ class TwitterOAuthClient extends OAuthClient
|
||||
|
||||
function favoritesDestroy($id)
|
||||
{
|
||||
$url = "http://api.twitter.com/1/favorites/destroy/$id.json";
|
||||
$response = $this->oAuthPost($url);
|
||||
$url = "http://api.twitter.com/1.1/favorites/destroy.json";
|
||||
$params=array();
|
||||
$params['id'] = $id;
|
||||
$response = $this->oAuthPost($url,$params);
|
||||
$status = json_decode($response);
|
||||
return $status;
|
||||
}
|
||||
@ -356,7 +362,7 @@ class TwitterOAuthClient extends OAuthClient
|
||||
|
||||
function statusesDestroy($id)
|
||||
{
|
||||
$url = "http://api.twitter.com/1/statuses/destroy/$id.json";
|
||||
$url = "http://api.twitter.com/1.1/statuses/destroy/$id.json";
|
||||
$response = $this->oAuthPost($url);
|
||||
$status = json_decode($response);
|
||||
return $status;
|
||||
|
Loading…
Reference in New Issue
Block a user