3 * StatusNet, the distributed open-source microblogging tool
7 * LICENCE: This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @author Brion Vibber <brion@status.net>
23 * @copyright 2010 StatusNet, Inc.
24 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25 * @link http://status.net/
28 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
31 $longoptions = array('nick=','import','all');
33 $helptext = <<<ENDOFHELP
34 USAGE: fakestream.php -n <username>
36 -n --nick=<username> Local user whose Twitter timeline to watch
37 --import Experimental: run incoming messages through import
38 --all Experimental: run multiuser; requires nick be the app owner
40 Attempts a User Stream connection to Twitter as the given user, dumping
45 require_once INSTALLDIR.'/scripts/commandline.inc';
47 if (have_option('n')) {
48 $nickname = get_option_value('n');
49 } else if (have_option('nick')) {
50 $nickname = get_option_value('nickname');
59 * @return TwitterOAuthClient
61 function twitterAuthForUser(User $user)
63 $flink = Foreign_link::getByUserID($user->id,
66 throw new ServerException("No Twitter config for this user.");
69 $token = TwitterOAuthClient::unpackToken($flink->credentials);
71 throw new ServerException("No Twitter OAuth credentials for this user.");
74 return new TwitterOAuthClient($token->key, $token->secret);
78 * Emulate the line-by-line output...
80 * @param Foreign_link $flink
83 function dumpMessage($flink, $data)
85 $msg->for_user = $flink->foreign_id;
86 $msg->message = $data;
87 print json_encode($msg) . "\r\n";
90 if (have_option('all')) {
91 throw new Exception('--all not yet implemented');
94 $user = User::staticGet('nickname', $nickname);
95 $auth = twitterAuthForUser($user);
96 $flink = Foreign_link::getByUserID($user->id,
99 $friends->friends = $auth->friendsIds();
100 dumpMessage($flink, $friends);
102 $timeline = $auth->statusesHomeTimeline();
103 foreach ($timeline as $status) {
104 dumpMessage($flink, $status);