There is api twitter c with which I work through a script:

var arrtweets = []; var x; //Function url formater function url(searchTerm, numOfTweets){ result = 'http://catcoin.ru/twitter.php?q=' + searchTerm + '&count='+ numOfTweets; return result; } // API Sendler var get100Tweet = function(data) { $.each(data.statuses, function(index, item) { arrtweets.push(item.text); }); x = Math.floor((Math.random() * 100) + 1); y = arrtweets[x].toString(); $('#list').html(y); }; function TweetRandom(name) { document.getElementById("list").innerHTML = $.get(url(name,100),get100Tweet); } 

I need instead of the search results to get the latest user tweets that api allows

 <?php $http_origin = $_SERVER['HTTP_ORIGIN']; if ( strrpos($http_origin, "catcoin.ru") || strrpos($http_origin, "jsfiddle.net") ){ header("Access-Control-Allow-Origin: $http_origin"); } header('Content-Type: application/json'); ini_set('display_errors', 1); require_once('TwitterAPIExchange.php'); /** Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array( 'oauth_access_token' => "", 'oauth_access_token_secret' => "", 'consumer_key' => "", 'consumer_secret' => "" ); /** Perform a GET request and echo the response **/ /** Note: Set the GET field BEFORE calling buildOauth(); **/ $url = 'https://api.twitter.com/1.1/search/tweets.json'; $getfield = '?'.$_SERVER['QUERY_STRING']; $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($settings); $api_response = $twitter ->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(); echo $api_response; 

https://gist.github.com/anonymous/234284d3eb6817969d9e04e497f5ad4a

  • and what in twitter.php? - L. Vadim
  • Unfortunately, I can’t add php code yet, I’ll add it in the late afternoon. - Basil Jimmy
  • Write here when you add, thanks - L. Vadim
  • Completed php files - Basil Jimmy

1 answer 1

Unfortunately I did not find how to do it in pure php, but I found a library that receives this data.

https://github.com/thujohn/twitter/

You can also connect via composer:

 composer require thujohn/twitter 

In my case, the call is:

  <?php echo Twitter::getUserTimeline(['screen_name' => 'vdvwolf', 'count' => 200, 'format' => 'json']);