3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php //INCLUDE YOUR LIST OF TWEETS AS AN ARRAY SIMILAR TO THE FOLLOWING $tweets = array( "524980794709016576", "524980794503495680", "524980792699940864" ); define('CONSUMER_KEY', "sHKRfEvXFJ3Avr3OWbkdIhkjV"); define('CONSUMER_SECRET', "HmNw6VbkFVHGObjCzYOqynz9V8NdIYlgnRcJ8K2sclLnD44dUv"); $x = base64_encode(rawurlencode(CONSUMER_KEY). ":".rawurlencode(CONSUMER_SECRET)); $url = "https://api.twitter.com/oauth2/token"; $opts = array( 'http'=>array( 'method'=>"POST", 'header'=>"Authorization:Basic $x\r\n". "Content-Type: application/x-www-form-urlencoded;charset=UTF-8.", 'content'=>"grant_type=client_credentials" ) ); $context = stream_context_create($opts); $output = file_get_contents($url,false,$context); $result = json_decode($output,true); $access_token = $result['access_token']; $query = urlencode("alibaba"); //include your query $search_url = "https://api.twitter.com/1.1/search/tweets.json?q=$query&result_type=recent&count=10"; $output = file_get_contents($search_url,false,stream_context_create(array( 'http'=>array( 'method'=>"GET", 'header'=>"Authorization:Bearer $access_token")))); $results = json_decode($output,true); //results returned as JSON $results = $results['statuses']; $c= 0; foreach ($results as $result) { $id = $result['id_str']; print $id; print "!!!"; $RTCount = $result['retweet_count']; if ($RTCount > 0) { $RTid = $result['retweeted_status']['id_str']; $tweet_url = "https://api.twitter.com/1.1/statuses/retweets/$RTid.json?count=1"; $output = file_get_contents($tweet_url,false,stream_context_create(array( 'http'=>array( 'method'=>"GET", 'header'=>"Authorization:Bearer $access_token")))); $retweets = json_decode($output,true); //results returned as JSON $last_RT = $retweets[0]['retweet_count']; } else { $last_RT = "!!!"; } //print "$tw\t$id\t$RTCount\t$last_RT\n"; } ?>
Output for 5.5.24 - 5.5.32, 5.5.34 - 5.6.17, 5.6.20 - 5.6.21, 7.0.0 - 7.0.3, 7.0.5 - 7.1.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/i0fkM on line 25 Warning: file_get_contents(https://api.twitter.com/oauth2/token): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/i0fkM on line 25 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/i0fkM on line 35 Warning: file_get_contents(https://api.twitter.com/1.1/search/tweets.json?q=alibaba&result_type=recent&count=10): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/i0fkM on line 35 Warning: Invalid argument supplied for foreach() in /in/i0fkM on line 39
Output for 5.4.35 - 5.4.45, 5.5.33, 5.6.18 - 5.6.19, 7.0.4
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/i0fkM on line 25 Warning: file_get_contents(https://api.twitter.com/oauth2/token): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/i0fkM on line 25 Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/i0fkM on line 35 Warning: file_get_contents(https://api.twitter.com/1.1/search/tweets.json?q=alibaba&result_type=recent&count=10): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/i0fkM on line 35 Warning: Invalid argument supplied for foreach() in /in/i0fkM on line 39
Output for hhvm-3.10.0 - 3.12.0
Warning: Failed to open https://api.twitter.com/oauth2/token (Could not resolve host: api.twitter.com) in /in/i0fkM on line 25 Warning: Failed to open https://api.twitter.com/1.1/search/tweets.json?q=alibaba&result_type=recent&count=10 (Could not resolve host: api.twitter.com) in /in/i0fkM on line 35 Warning: Invalid argument supplied for foreach() in /in/i0fkM on line 58
Output for 5.3.0 - 5.4.34
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/i0fkM on line 25 Warning: file_get_contents(https://api.twitter.com/oauth2/token): failed to open stream: No such file or directory in /in/i0fkM on line 25 Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/i0fkM on line 35 Warning: file_get_contents(https://api.twitter.com/1.1/search/tweets.json?q=alibaba&result_type=recent&count=10): failed to open stream: No such file or directory in /in/i0fkM on line 35 Warning: Invalid argument supplied for foreach() in /in/i0fkM on line 39
Output for 5.2.0 - 5.2.17
Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/i0fkM on line 25 Warning: file_get_contents(https://api.twitter.com/oauth2/token): failed to open stream: No such file or directory in /in/i0fkM on line 25 Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/i0fkM on line 35 Warning: file_get_contents(https://api.twitter.com/1.1/search/tweets.json?q=alibaba&result_type=recent&count=10): failed to open stream: No such file or directory in /in/i0fkM on line 35 Warning: Invalid argument supplied for foreach() in /in/i0fkM on line 39
Output for 5.0.0 - 5.1.6
Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/i0fkM on line 25 Warning: file_get_contents(https://api.twitter.com/oauth2/token): failed to open stream: No such file or directory in /in/i0fkM on line 25 Fatal error: Call to undefined function json_decode() in /in/i0fkM on line 26
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Warning: file_get_contents() expects at most 2 parameters, 3 given in /in/i0fkM on line 25 Fatal error: Call to undefined function: json_decode() in /in/i0fkM on line 26
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Warning: file_get_contents() expects at most 2 parameters, 3 given in /in/i0fkM on line 25 Fatal error: Call to undefined function: json_decode() in /in/i0fkM on line 26
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: file_get_contents() expects at most 2 parameters, 3 given in /in/i0fkM on line 25 Fatal error: Call to undefined function: json_decode() in /in/i0fkM on line 26