Hi
Today we will learn how to get a user's tweets in json format in laravel 5.
Add the below line of code in your composer.json file.
{
"require": {
"j7mbo/twitter-api-php": "dev-master"
}
}
And then update your composer with composer update command in your terminal.
Then in any controller where you want to get tweets, use below function.
public function twitter(){
$settings = array(
'oauth_access_token' => 'Your oauth access token',
'oauth_access_token_secret' => 'Your oauth access token secret',
'consumer_key' => 'Your consumer key',
'consumer_secret' => 'Your consumer secret'
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '';
$requestMethod = 'GET';
$twitter = new \TwitterAPIExchange($settings);
$feeds = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
return json_encode($feeds);
}
Please click or goto url https://themepacific.com/how-to-generate-api-key-consumer-token-access-key-for-twitter-oauth/994/, to generate your settings.
In above script if we use $getfield = '?user_id={user_id}', it will give tweets of that particular user. If it is left blank then it will give tweets of that user whom oauth access token belongs to. If you want to explore more then please goto url https://dev.twitter.com/rest/reference/get/statuses/user_timeline.
Hope it will help someone.
Thanks
Today we will learn how to get a user's tweets in json format in laravel 5.
Add the below line of code in your composer.json file.
{
"require": {
"j7mbo/twitter-api-php": "dev-master"
}
}
And then update your composer with composer update command in your terminal.
Then in any controller where you want to get tweets, use below function.
public function twitter(){
$settings = array(
'oauth_access_token' => 'Your oauth access token',
'oauth_access_token_secret' => 'Your oauth access token secret',
'consumer_key' => 'Your consumer key',
'consumer_secret' => 'Your consumer secret'
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '';
$requestMethod = 'GET';
$twitter = new \TwitterAPIExchange($settings);
$feeds = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
return json_encode($feeds);
}
Please click or goto url https://themepacific.com/how-to-generate-api-key-consumer-token-access-key-for-twitter-oauth/994/, to generate your settings.
In above script if we use $getfield = '?user_id={user_id}', it will give tweets of that particular user. If it is left blank then it will give tweets of that user whom oauth access token belongs to. If you want to explore more then please goto url https://dev.twitter.com/rest/reference/get/statuses/user_timeline.
Hope it will help someone.
Thanks
No comments:
Post a Comment