troubleshooting Question

php script to extract tweets from json data

Avatar of madstylex
madstylex asked on
LinuxPHPScripting Languages
11 Comments3 Solutions1560 ViewsLast Modified:
I have a script in linux mint that fetches twitter statuses using the following input from the command line:

php twitter.php show username number

The script returns the output in JSON format.

How can I add to this script so that it removes the twitter statuses only from the json data and displays  them in a list?

The code is shown below (my developer token data has been removed).

<?php

session_start();
require_once("twitteroauth.php"); //Path to twitteroauth library



$task = $argv[1];
$twitteruser = $argv[2];
$twitterkeyword = $argv[2];
$notweets = $argv[3];
$consumerkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$consumersecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$accesstoken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$accesstokensecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

if ($task == "show") {
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}

$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

//if ($task == "show") {

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);

echo json_encode($tweets);
//echo $tweets;
}

echo $notweets
?>
ASKER CERTIFIED SOLUTION
rinfo

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros