PHP code example of pingpong / twitter
1. Go to this page and download the library: Download pingpong/twitter library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pingpong / twitter example snippets
'Pingpong\Twitter\TwitterServiceProvider'
'Twitter' => 'Pingpong\Twitter\Facades\Twitter',
return array(
'consumer_key' => '',
'consumer_secret' => '',
'oauth_token' => null,
'oauth_token_secret'=> null,
'bearer_token' => null,
'callback_url' => url('twitter/callback'),
'fallback_url' => url('/')
);
Twitter::authorize();
Twitter::authenticate();
$callbackUrl = url('twitter/getcallback');
Twitter::authorize($callbackUrl);
Twitter::authenticate($callbackUrl);
Twitter::getCallback();
// or using `callback` method
Twitter::callback();
Twitter::getAccountVerifyCredentials();
// you can also specify what parameters want you use
$parameters = array();
Twitter::getAccountVerifyCredentials($parameters);
// or using `getCredentials` method
Twitter::getCredentials($parameters);
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);
Twitter::get('/path', $parameters);
Twitter::post('/path', $parameters);
Twitter::put('/path', $parameters);
Twitter::patch('/me', $parameters);
Twitter::delete('/me', $parameters);
Twitter::format('json');
Twitter::format('array');
Twitter::format('object');
Twitter::enableCurl();
Twitter::disableCurl();
Twitter::setConnectionTimeout(2000);
Twitter::setTimeout(500);
Twitter::xAuth($username, $password);
Twitter::setToken($oauthToken, $oauthTokenSecret);
$token = Twitter::getBearerToken();
Twitter::setBearerToken($token);
Route::get('twitter/authenticate', function()
{
return Twitter::authenticate();
});
Route::get('twitter/authorize', function()
{
return Twitter::authorize();
});
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());
}
});
Route::get('twitter/logout', function()
{
Twitter::logout();
return Redirect::home();
});
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());
}
});
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());
}
});
Twitter::getStatusesMentionsTimeline($parameters, $multipart, $appOnlyAuth);
Twitter::getStatusesUserTimeline($parameters, $multipart, $appOnlyAuth);
Twitter::getStatusesHomeTimeline($parameters, $multipart, $appOnlyAuth);
Twitter::getStatusesRetweetsOfMe($parameters, $multipart, $appOnlyAuth);
Twitter::getStatusesRetweets($id, $parameters, $multipart, $appOnlyAuth);
Twitter::getStatusesShow($id, $parameters, $multipart, $appOnlyAuth);
Twitter::postStatusesDestroy($id, $parameters, $multipart, $appOnlyAuth);
Twitter::postStatusesUpdate($parameters, $multipart, $appOnlyAuth);
Twitter::postStatusesRetweet($id, $parameters, $multipart, $appOnlyAuth);
Twitter::postStatusesUpdateWithMedia($parameters, $appOnlyAuth);
Twitter::getStatusesOembed($parameters, $multipart, $appOnlyAuth);
Twitter::getStatusesRetweetersIds($parameters, $multipart, $appOnlyAuth);
Twitter::getSearchTweets($parameters, $multipart, $appOnlyAuth);
Twitter::getSearchTweets($parameters, $multipart, $appOnlyAuth);
Twitter::getDirectMessages($parameters, $multipart, $appOnlyAuth);
Twitter::getDirectMessagesSent($parameters, $multipart, $appOnlyAuth);
Twitter::getDirectMessagesShow($parameters, $multipart, $appOnlyAuth);
Twitter::postDirectMessagesDestroy($parameters, $multipart, $appOnlyAuth);
Twitter::postDirectMessagesNew($parameters, $multipart, $appOnlyAuth);
Twitter::getFavoritesList($parameters, $multipart, $appOnlyAuth);
Twitter::postFavoritesDestroy($parameters, $multipart, $appOnlyAuth);
Twitter::postFavoritesCreate($parameters, $multipart, $appOnlyAuth);
php artisan vendor:publish --provider="Pingpong\Twitter\TwitterServiceProvider"