Package Data | |
---|---|
Maintainer Username: | gravitano |
Maintainer Contact: | pingpong.labs@gmail.com (Pingpong Labs) |
Package Create Date: | 2014-02-13 |
Package Last Update: | 2016-03-13 |
Home Page: | https://packagist.org/packages/pingpong/twitter |
Language: | PHP |
License: | BSD-3-Clause |
Last Refreshed: | 2024-12-22 03:17:10 |
Package Statistics | |
---|---|
Total Downloads: | 43,061 |
Monthly Downloads: | 608 |
Daily Downloads: | 3 |
Total Stars: | 30 |
Total Watchers: | 8 |
Total Forks: | 10 |
Total Open Issues: | 2 |
Require PHP 5.4+ or higher.
For Laravel 4.* please use version
1.*
.
Open your composer.json file, and add the new required package.
"pingpong/twitter": "~2"
Next, open a terminal and run.
composer update
After the composer updated. Add new service provider in app/config/app.php.
'Pingpong\Twitter\TwitterServiceProvider'
Next, Add new alias.
'Twitter' => 'Pingpong\Twitter\Facades\Twitter',
Next, open a terminal and run.
php artisan vendor:publish --provider="Pingpong\Twitter\TwitterServiceProvider"
Done.
return array(
'consumer_key' => '',
'consumer_secret' => '',
'oauth_token' => null,
'oauth_token_secret'=> null,
'bearer_token' => null,
'callback_url' => url('twitter/callback'),
'fallback_url' => url('/')
);
Authorize the user.
Twitter::authorize();
Authenticate the user.
Twitter::authenticate();
You can also override the callback url when authorize or authenticate the user.
$callbackUrl = url('twitter/getcallback');
Twitter::authorize($callbackUrl);
Twitter::authenticate($callbackUrl);
Get callback after authorize or authenticate the user.
Twitter::getCallback();
// or using `callback` method
Twitter::callback();
Get account verify credentials.
Twitter::getAccountVerifyCredentials();
// you can also specify what parameters want you use
$parameters = array();
Twitter::getAccountVerifyCredentials($parameters);
// or using `getCredentials` method
Twitter::getCredentials($parameters);
Global API call.
Twitter::api($method, $path, $parameters, $multipart, $appOnlyAuth);
Twitter::api('GET', '/path');
Twitter::api('POST', '/path', $parameters);
Twitter::api('PUT', '/path', $parameters);
Twitter::api('PATCH', '/path', $parameters);
Twitter::api('DELETE', '/path/to', $parameters);
Helper method for call Twitter API.
GET Request
Twitter::get('/path', $parameters);
POST Request
Twitter::post('/path', $parameters);
PUT Request
Twitter::put('/path', $parameters);
PATCH Request
Twitter::patch('/me', $parameters);
DELETE Request
Twitter::delete('/me', $parameters);
Set return format.
Twitter::format('json');
Twitter::format('array');
Twitter::format('object');
Enable and disable curl.
Twitter::enableCurl();
Twitter::disableCurl();
Set connection and request timeout.
Twitter::setConnectionTimeout(2000);
Twitter::setTimeout(500);
Allows a Consumer application to exchange the OAuth Request Token for an OAuth Access Token with xAuth.
Twitter::xAuth($username, $password);
Set token.
Twitter::setToken($oauthToken, $oauthTokenSecret);
Get bearer token.
$token = Twitter::getBearerToken();
Set bearer token.
Twitter::setBearerToken($token);
Authenticate the user.
Route::get('twitter/authenticate', function()
{
return Twitter::authenticate();
});
Authorize the user.
Route::get('twitter/authorize', function()
{
return Twitter::authorize();
});
Get twitter callback.
Route::get('twitter/callback', function()
{
try
{
$callback = Twitter::getCallback();
dd($callback);
}
catch(Pingpong\Twitter\Exceptions\TwitterApiException $e)
{
var_dump($e->getMessage());
var_dump($e->getResponse());
}
});
Logout the user.
Route::get('twitter/logout', function()
{
Twitter::logout();
return Redirect::home();
});
Post tweet.
Route::get('twitter/tweet', function()
{
try
{
$status = 'Hello world!';
$response = Twitter::tweet($status);
dd($response);
}
catch(Pingpong\Twitter\Exceptions\TwitterApiException $e)
{
var_dump($e->getMessage());
var_dump($e->getResponse());
}
});
Upload media.
Route::get('twitter/upload', function()
{
try
{
$status = 'Hello world!';
$media = '/path/to/your-media.ext';
$response = Twitter::upload($status, $media);
dd($response);
}
catch(Pingpong\Twitter\Exceptions\TwitterApiException $e)
{
var_dump($e->getMessage());
var_dump($e->getResponse());
}
});
Timelines are collections of Tweets, ordered with the most recent first.
Returns the 20 most recent mentions (tweets containing a users's @screen_name) for the authenticating user.
Twitter::getStatusesMentionsTimeline($parameters, $multipart, $appOnlyAuth);
Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters.
Twitter::getStatusesUserTimeline($parameters, $multipart, $appOnlyAuth);
Returns a collection of the most recent Tweets and retweets posted by the authenticating user and the users they follow.
Twitter::getStatusesHomeTimeline($parameters, $multipart, $appOnlyAuth);
Returns the most recent tweets authored by the authenticating user that have been retweeted by others.
Twitter::getStatusesRetweetsOfMe($parameters, $multipart, $appOnlyAuth);
Tweets are the atomic building blocks of Twitter, 140-character status updates with additional associated metadata.
Returns a collection of the 100 most recent retweets of the tweet specified by the id parameter.
Twitter::getStatusesRetweets($id, $parameters, $multipart, $appOnlyAuth);
Returns a single Tweet, specified by the id parameter.
Twitter::getStatusesShow($id, $parameters, $multipart, $appOnlyAuth);
Destroys the status specified by the required ID parameter.
Twitter::postStatusesDestroy($id, $parameters, $multipart, $appOnlyAuth);
Updates the authenticating user's current status, also known as tweeting.
Twitter::postStatusesUpdate($parameters, $multipart, $appOnlyAuth);
Retweets a tweet.
Twitter::postStatusesRetweet($id, $parameters, $multipart, $appOnlyAuth);
Updates the authenticating user's current status and attaches media for upload.
Twitter::postStatusesUpdateWithMedia($parameters, $appOnlyAuth);
Returns information allowing the creation of an embedded representation of a Tweet on third party sites.
Twitter::getStatusesOembed($parameters, $multipart, $appOnlyAuth);
Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.
Twitter::getStatusesRetweetersIds($parameters, $multipart, $appOnlyAuth);
Find relevant Tweets based on queries performed by your users.
Returns a collection of relevant Tweets matching a specified query.
Twitter::getSearchTweets($parameters, $multipart, $appOnlyAuth);
Direct Messages are short, non-public messages sent between two users.
Twitter::getSearchTweets($parameters, $multipart, $appOnlyAuth);
Returns the 20 most recent direct messages sent to the authenticating user.
Twitter::getDirectMessages($parameters, $multipart, $appOnlyAuth);
Returns the 20 most recent direct messages sent by the authenticating user.
Twitter::getDirectMessagesSent($parameters, $multipart, $appOnlyAuth);
Returns a single direct message, specified by an id parameter.
Twitter::getDirectMessagesShow($parameters, $multipart, $appOnlyAuth);
Destroys the direct message specified in the required ID parameter.
Twitter::postDirectMessagesDestroy($parameters, $multipart, $appOnlyAuth);
Sends a new direct message to the specified user from the authenticating user.
Twitter::postDirectMessagesNew($parameters, $multipart, $appOnlyAuth);
Users favorite tweets to give recognition to awesome tweets, to curate the best of Twitter, to save for reading later, and a variety of other reasons. Likewise, developers make use of "favs" in many different ways.
Returns the 20 most recent Tweets favorited by the authenticating or specified user.
Twitter::getFavoritesList($parameters, $multipart, $appOnlyAuth);
Un-favorites the status specified in the ID parameter as the authenticating user.
Twitter::postFavoritesDestroy($parameters, $multipart, $appOnlyAuth);
Favorites the status specified in the ID parameter as the authenticating user.
Twitter::postFavoritesCreate($parameters, $multipart, $appOnlyAuth);
NOTE: Not all functions and Facade APIs documented
This package is open-sourced software licensed under The BSD 3-Clause License