Very new to PHP coding - I've set up a server based MySQL database to insert twitter api data into.
I can retrieve twitter api data and profile it on the web (http://www.pdanalytics.ca/StephenHarperTweets.php). Using PHP, how do I insert it into my database.
I've googled, and made attempts based on general tutorials, but still feel pretty far off what I believe should be a fairly straight forward task.
Thanks.
Here is my code:
<?php
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "xxxxxxxxxxxxxxx",
'oauth_access_token_secret' => "xxxxxxxxxxxxxxx",
'consumer_key' => "xxxxxxxxxxxxx",
'consumer_secret' => "xxxxxxxxxxxxxxxxxxx"
);
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$requestMethod = "GET";
$getfield = '?screen_name=pmharper&count=20';
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
if($string["errors"][0]["message"] != "") {echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p> <em>".$string[errors][0]["message"]."</em></p>";exit();}
foreach($string as $items)
{
echo "Tweeted by: ". $items['user']['name']."<br />";
echo "Screen name: ". $items['user']['screen_name']."<br />";
echo "Tweet: ". $items['text']."<br />";
echo "Time and Date of Tweet: ".$items['created_at']."<br />";
echo "Tweet ID: ".$items['id_str']."<br />";
echo "Followers: ". $items['user']['followers_count']."<br /><hr />";
}
?>