I hope that you can help me with this one. Basically what I am doing, is adding tweets to my twitter account through api from my website administration panel.
It all works fine, BUT I cannot store the info to database because the json_decode variable that I have returns a NULL. I do not understand what is the appropriate way to get the info from twitter json.
Here is my code:
$settings = array(
'oauth_access_token' => $oauth_access_token,
'oauth_access_token_secret' => $oauth_access_token_secret,
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret
);
$connection = new TwitterAPIExchange($settings);
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$requestMethod = "POST";
$user = $twitter_user;
$postfields = array(
'screen_name' => $user,
'status' => $twit );
$connection->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
// get the contents of the JSON file
$jsonCont = file_get_contents($connection);
//decode JSON data to PHP array
$content = json_decode($jsonCont, true);
$conn = new mysqli($server, $username, $password, $database);
$id = $content['id'];
$created = $content['created_at'];
$tweet = $content['text'];
$by = $content['user']['name'];
$sql = "INSERT INTO `twitter` (`idtwit`, `tweet`, `tweetedby`, `datet`) VALUES ('".$id."', '".$tweet."', '".$by."', '".$created."')";
$conn->query($sql);
echo "<br /><div class='alert alert-info'>New record updated successfully</div>";
$conn->close();
How to use json_decode properly with this ?!
I have also tried to wrap it around the $connection request like so, eliminating my variable, but then, it will not post to twitter anymore.
$connection->json_decode(buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest(),$assoc = TRUE);