I use the code below to get my tweets and echo json. It works great.
<?php session_start(); require_once('includes/twitter/twitteroauth.php'); $twitteruser = "xxxxxx"; $notweets = 3; $consumerkey = "xxxxxxx"; $consumersecret = "xxxxxx"; $accesstoken = "xxxxxxxx"; $accesstokensecret = "xxxxxx"; $connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets); echo json_encode($tweets); ?>
Now I want to send a tweet using a similar code, but it does not work. I am not sure if the send syntax is correct. so please help me.
<?php session_start(); require_once('includes/twitter/twitteroauth.php'); //Path to twitteroauth library $twitteruser = "xxxxxx"; $notweets = 3; $consumerkey = "xxxxxxx"; $consumersecret = "xxxxxx"; $accesstoken = "xxxxxxxx"; $accesstokensecret = "xxxxxx"; // start connection $connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); //message $message = "Hi how are you"; //send message $status = $connection->post('https://api.twitter.com/1.1/statuses/update.json', array('status' => $message)); ?>
source share