Simply extended from RuntimeException
.
Treats errors caused on Twitter.
Some TwistOAuth
methods return an instance of TwistMedia
when the following types of header is detected.
Content-Type: image/***
Content-Type: video/***
(string) $media->type
Readonly.
Content-Type. This means the following value.
'image/***'
'video/***'
(string) $media->data
Readonly.
This means binary media data.
(string) $media->getDataUri()
Data URI. This means the following value.
'data:image/***;base64,......'
'data:video/***;base64,......'
All properties are Readonly.
(string) $to->ck // consumer_key
(string) $to->cs // consumer_secret
(string) $to->ot // oauth_token (request_token or access_token)
(string) $to->os // oauth_token_secret (request_token_secret or access_token_secret)
Constructor.
new TwistOAuth($ck, $cs, $ot = '', $os = '')
- (string) $ck
consumer_key. - (string) $cs
consumer_secret. - (string) $ot
oauth_token. (request_token or access_token) - (string) $os
oauth_token_secret. (request_token_secret or access_token_secret)
Easily generate URL for users to login.
(string) $to->getAuthenticateUrl($force_login = false)
(string) $to->getAuthorizeUrl($force_login = false)
- (bool) $force_login
Whether we force logined users to relogin.
A URL for authentication or authorization.
TwistOAuth::renewWithRequestToken()
TwistOAuth::renewWithAccessToken()
TwistOAuth::renewWithAccessTokenX()
Fetch tokens and regenerate instance with them.
(TwistOAuth) $to->renewWithRequestToken($oauth_callback = '', $proxy = '')
(TwistOAuth) $to->renewWithAccessToken($oauth_verifier, $proxy = '')
(TwistOAuth) $to->renewWithAccessTokenX($username, $password, $proxy = '')
- (string) $oauth_callback
- (string) $oauth_verifier
- (string) $username
screen_name or email. - (string) $password
- (string) $proxy
Full proxy URL.
e.g.https://111.222.333.444:8080
A new TwistOAuth
instance.
Throws TwistException
.
Execute a request for Twitter.
(mixed) $to->get($url, $params = array(), $proxy = '')
(mixed) $to->post($url, $params = array(), $proxy = '')
(mixed) $to->postMultipart($url, $params = array(), $proxy = '')
- (string) $url
Full or partial endpoint URL.
e.g.statuses/update
https://api.twitter.com/1.1/statuses/update.json
- (mixed) $params
1-demensional array or query string.
File path annotation is@
on key.
File data annotation is#
on key.NULL
is ignored. - (string) $proxy
Full proxy URL.
e.g.https://111.222.333.444:8080
Example value of $params:
$params = 'status=test&in_reply_to_status_id=123456';
$params = array(
'status' => 'test',
'in_reply_to_status_id' => '123456',
);
$params = array(
'status' => 'test',
'@media[]' => 'test.jpg',
);
$params = array(
'status' => 'test',
'#media[]' => file_get_contents('test.jpg'),
);
Return value will mainly be stdClass
, array or TwistMedia
.
Throws TwistException
.
Execute a request for third party sites using OAuth Echo.
(mixed) $to->getOut($url, $params = array(), $proxy = '')
(mixed) $to->postOut($url, $params = array(), $proxy = '')
(mixed) $to->postMultipartOut($url, $params = array(), $proxy = '')
- (string) $url
Full URL.
e.g.http://api.twitpic.com/2/upload.json
- (mixed) $params
1-demensional array or query string.
File path annotation is@
on key.
File data annotation is#
on key.NULL
is ignored. - (string) $proxy
Full proxy URL.
e.g.https://111.222.333.444:8080
Return value will mainly be stdClass
, array or TwistMedia
.
Throws TwistException
.
Execute a streaming request for Twitter.
(void) $to->streaming($url, callable $callback, $params = array(), $proxy = '')
- (string) $url
Full or partial endpoint URL.
e.g.statuses/filter
https://stream.twitter.com/1.1/statuses/filter.json
- (callable) $callback
A callback function.
1 argument for each statuses.
Return true for disconnecting. - (mixed) $params
1-demensional array or query string.
File path annotation is@
on key.
File data annotation is#
on key.NULL
is ignored. - (string) $proxy
Full proxy URL.
e.g.https://111.222.333.444:8080
Example value of $callback:
// A callback closure, which displays tweets unlimitedly.
$callback = function ($status) {
// Treat only tweets
if (isset($status->text)) {
printf(
"@%s: %s\n",
$status->user->screen_name,
htmlspecialchars_decode($status->text, ENT_NOQUOTES)
);
flush(); // Required if running not on Command Line but on Apache
}
};
// A callback closure, which displays 10 tweets and then disconnect.
$callback = function ($status) {
static $i = 0;
if ($i > 10) {
// Return true for disconnecting.
return true;
}
// Treat only tweets
if (isset($status->text)) {
printf(
"@%s: %s\n",
$status->user->screen_name,
htmlspecialchars_decode($status->text, ENT_NOQUOTES)
);
++$i;
flush(); // Required if running not on Command Line but on Apache
}
};
Throws TwistException
.
Direct OAuth. (Scraping Login)
(TwistOAuth) TwistOAuth::login($ck, $cs, $username, $password, $proxy = '')
(TwistOAuth) $to->login($ck, $cs, $username, $password, $proxy = '')
- (string) $ck
consumer_key. - (string) $cs
consumer_secret. - (string) $username
screen_name or email. - (string) $password
- (string) $proxy
Full proxy URL.
e.g.https://111.222.333.444:8080
A new instance of TwistOAuth
.
Throws TwistException
.
Multiple Direct OAuth. (Scraping Logins)
(array) TwistOAuth::multiLogin(array $credentials, $throw_in_process = false)
(array) $to->multiLogin(array $credentials, $throw_in_process = false)
- (array) $credentials
See example. - (bool) $throw_in_process
See information about static TwistOAuth::curlMultiExec().
Example value of $credentials:
$credentials = array(
'YOUR SCREEN_NAME 0' => array(
'YOUR CONSUMER KEY 0',
'YOUR CONSUMER SECRET 0',
'YOUR SCREEN_NAME 0',
'YOUR PASSWORD 0',
),
'YOUR SCREEN_NAME 1' => array(
'YOUR CONSUMER KEY 1',
'YOUR CONSUMER SECRET 1',
'YOUR SCREEN_NAME 1',
'YOUR PASSWORD 1',
),
'YOUR SCREEN_NAME 2' => array(
'YOUR CONSUMER KEY 2',
'YOUR CONSUMER SECRET 2',
'YOUR SCREEN_NAME 2',
'YOUR PASSWORD 2',
),
...
);
An array consisting of the following structure.
$return_value = array(
'YOUR SCREEN_NAME 0' => new TwistOAuth(...),
'YOUR SCREEN_NAME 1' => new TwistOAuth(...),
'YOUR SCREEN_NAME 2' => new TwistOAuth(...),
...
);
Throws TwistException
.
TwistOAuth::curlPostRequestToken()
TwistOAuth::curlPostAccessToken()
TwistOAuth::curlGet()
TwistOAuth::curlGetOut()
TwistOAuth::curlPost()
TwistOAuth::curlPostOut()
TwistOAuth::curlPostMultipart()
TwistOAuth::curlPostMultipartOut()
TwistOAuth::curlStreaming()
(resource) $to->curlPostRequestToken($oauth_callback = '', $proxy = '')
(resource) $to->curlPostAccessToken($oauth_verifier, $proxy = '')
(resource) $to->curlGet($url, $params = array(), $proxy = '')
(resource) $to->curlGetOut($url, $params = array(), $proxy = '')
(resource) $to->curlPost($url, $params = array(), $proxy = '')
(resource) $to->curlPostOut($url, $params = array(), $proxy = '')
(resource) $to->curlPostMultipart($url, $params = array(), $proxy = '')
(resource) $to->curlPostMultipartOut($url, $params = array(), $proxy = '')
(resource) $to->curlStreaming($url, callable $callback, $params = array(), $proxy = '')
(Omitted)
A cURL resource.
(array) TwistOAuth::curlMultiExec(array $curls, $throw_in_process = false)
(array) $to->curlMultiExec(array $curls, $throw_in_process = false)
(void) TwistOAuth::curlMultiStreaming(array $curls) // $throw_in_process is always true
(void) $to->curlMultiStreaming(array $curls) // $throw_in_process is always true
- (array) $curls
An array of cURL resources. - (bool) $throw_in_process
See below.
Example:
try {
$throw_in_process = /* true or false*/ ;
$result = $to->curlMultiExec(array(
'a' => $to->curlGet('users/show', array(
'screen_name' => 'foofoofoobarbarbarbazbazbaz', // invalid screen_name
)),
'b' => $to->curlGet('users/show', array(
'screen_name' => 'twitter', // valid screen_name
)),
), $throw_in_process);
echo "Flow A\n";
foreach ($result as $k => $v) {
printf("[%s] %s\n", $k, $v instanceof stdClass ? $v->screen_name : $v->getMessage());
}
} catch (TwistException $e) {
echo "Flow B\n";
printf("%s\n", $e->getMessage());
}
If $throw_in_process is false...
Flow A
[a] Sorry, that page does not exist
[b] twitter
If $throw_in_process is true...
Flow B
(a) Sorry, that page does not exist