2009-08-01 17:20:44 +09:00
|
|
|
<?php
|
|
|
|
|
2009-08-04 09:46:18 +09:00
|
|
|
class TwitterOAuthClient extends OAuthClient
|
2009-08-01 17:20:44 +09:00
|
|
|
{
|
|
|
|
public static $requestTokenURL = 'https://twitter.com/oauth/request_token';
|
|
|
|
public static $authorizeURL = 'https://twitter.com/oauth/authorize';
|
|
|
|
public static $accessTokenURL = 'https://twitter.com/oauth/access_token';
|
|
|
|
|
|
|
|
function __construct($oauth_token = null, $oauth_token_secret = null)
|
|
|
|
{
|
|
|
|
$consumer_key = common_config('twitter', 'consumer_key');
|
|
|
|
$consumer_secret = common_config('twitter', 'consumer_secret');
|
|
|
|
|
2009-08-04 09:46:18 +09:00
|
|
|
parent::__construct($consumer_key, $consumer_secret,
|
|
|
|
$oauth_token, $oauth_token_secret);
|
2009-08-01 17:20:44 +09:00
|
|
|
}
|
|
|
|
|
2009-08-04 09:46:18 +09:00
|
|
|
function getAuthorizeLink($request_token) {
|
|
|
|
return parent::getAuthorizeLink($request_token,
|
|
|
|
common_local_url('twitterauthorization'));
|
2009-08-01 17:20:44 +09:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify_credentials()
|
|
|
|
{
|
|
|
|
$url = 'https://twitter.com/account/verify_credentials.json';
|
|
|
|
$response = $this->oAuthGet($url);
|
|
|
|
$twitter_user = json_decode($response);
|
|
|
|
return $twitter_user;
|
|
|
|
}
|
|
|
|
|
2009-08-04 07:46:01 +09:00
|
|
|
function statuses_update($status, $in_reply_to_status_id = null)
|
|
|
|
{
|
|
|
|
$url = 'https://twitter.com/statuses/update.json';
|
|
|
|
$params = array('status' => $status,
|
|
|
|
'in_reply_to_status_id' => $in_reply_to_status_id);
|
|
|
|
$response = $this->oAuthPost($url, $params);
|
|
|
|
$status = json_decode($response);
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
2009-08-04 11:21:18 +09:00
|
|
|
function statuses_friends_timeline($since_id = null, $max_id = null,
|
|
|
|
$cnt = null, $page = null) {
|
|
|
|
|
2009-08-05 02:19:05 +09:00
|
|
|
$url = 'https://twitter.com/statuses/friends_timeline.json';
|
2009-08-04 11:21:18 +09:00
|
|
|
$params = array('since_id' => $since_id,
|
|
|
|
'max_id' => $max_id,
|
|
|
|
'count' => $cnt,
|
|
|
|
'page' => $page);
|
|
|
|
$qry = http_build_query($params);
|
|
|
|
|
|
|
|
if (!empty($qry)) {
|
|
|
|
$url .= "?$qry";
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $this->oAuthGet($url);
|
|
|
|
$statuses = json_decode($response);
|
|
|
|
return $statuses;
|
|
|
|
}
|
|
|
|
|
2009-08-06 16:03:05 +09:00
|
|
|
function statuses_friends($id = null, $user_id = null, $screen_name = null,
|
|
|
|
$page = null)
|
|
|
|
{
|
|
|
|
$url = "https://twitter.com/statuses/friends.json";
|
|
|
|
|
|
|
|
$params = array('id' => $id,
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'screen_name' => $screen_name,
|
|
|
|
'page' => $page);
|
|
|
|
$qry = http_build_query($params);
|
|
|
|
|
|
|
|
if (!empty($qry)) {
|
|
|
|
$url .= "?$qry";
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $this->oAuthGet($url);
|
|
|
|
$ids = json_decode($response);
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
function friends_ids($id = null, $user_id = null, $screen_name = null,
|
|
|
|
$page = null)
|
|
|
|
{
|
|
|
|
$url = "https://twitter.com/friends/ids.json";
|
|
|
|
|
|
|
|
$params = array('id' => $id,
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'screen_name' => $screen_name,
|
|
|
|
'page' => $page);
|
|
|
|
$qry = http_build_query($params);
|
|
|
|
|
|
|
|
if (!empty($qry)) {
|
|
|
|
$url .= "?$qry";
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = $this->oAuthGet($url);
|
|
|
|
$ids = json_decode($response);
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
|
2009-08-01 17:20:44 +09:00
|
|
|
}
|