Hij geeft telkens een 401, unauthorized melding. Ik kan echter niks fouts ontdekken. Mijn consumer Key en consumer secret zijn evenals de tokens niet veranderd.
Noot: ik werk met vaste tokens omdat er alleen opgehaald wordt. Niet gepost, dus alleen de applicatie heeft toegang tot Twitter.
Iemand hetzelfde? Of weet iemand een oplossing? Ik heb het idee dat de signature niet in orde is maar geen idee wat ik eraan kan doen.
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
include_once 'twitteroauth.php';
include_once '../../plugins/plugin.database.php';
// Get last update
$checkLastUpdate = $db->query('SELECT id, lastupdate FROM twitterUpdate WHERE lastupdate BETWEEN NOW() - INTERVAL 1 MINUTE AND NOW()');
if($checkLastUpdate->rowCount() == 0)
{
// Get last tweet
$selectLastTweet = $db->query('SELECT tweetID FROM twitterTweets ORDER BY created DESC LIMIT 0,1');
$getCount = $selectLastTweet->rowCount();
while($row = $selectLastTweet->fetch(PDO::FETCH_ASSOC)) $tweetID = $row['tweetID'];
// Set Twitter values
$consumerKey = 'xxxxxx';
$consumerSecret = 'xxxxxx';
$oauthToken = 'xxxxxx';
$oauthSecret = 'xxxxxx';
// Make connection to Twitter
$connection = new TwitterOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthSecret);
$content = $connection->get('1/account/verify_credentials');
$timeline = $connection->get('1/statuses/home_timeline');
$http_code = $connection->http_code;
if($http_code == 200)
{
// Build transition
$i = 0;
$db->beginTransaction();
// Loop through tweets
foreach($timeline as $tweet)
{
if($tweetID == $tweet->id) break;
$db->exec('INSERT INTO twitterTweets VALUES("", "'.strip_tags($tweet->source).'",
"'.date('Y-m-d H:i:s', strtotime($tweet->created_at)).'", "'.$tweet->id.'",
"'.$tweet->user->screen_name.'", "'.$tweet->user->name.'",
"'.$tweet->user->profile_image_url.'", "'.htmlentities($tweet->text).'")');
if(++$i == 5) break;
}
// Execute transaction
$db->commit();
$db->query('INSERT INTO twitterUpdate VALUES("", NOW())');
}
else
{
echo '<div class="error">';
switch($http_code)
{
case 400:
echo 'Foutcode 400: Bad Request, Twitter service is momenteel onbereikbaar.';
break;
case 401:
echo 'Foutcode 401: Unauthorized, u bent niet gemachtigd om deze bewerking uit te voeren.';
break;
case 500:
echo 'Foutcode 500: Internal Server Error, Twitter service is momenteel onbereikbaar.';
break;
case 502:
echo 'Foutcode 502: Bad Gateway, Twitter is momenteel onbereikbaar of overbezet.';
break;
case 503:
echo 'Foutcode 503: Service Unavailible, Twitter is over capacity';
break;
}
echo '</div>';
}
}
// Print the last 5 tweets in database
$selectTweets = $db->query('SELECT source, created, username, name, imageUrl, text FROM twitterTweets ORDER BY created DESC LIMIT 0,5');
while($row = $selectTweets->fetch(PDO::FETCH_ASSOC))
{
echo ' <div class="tweet">
<div class="content">
<a href="http://twitter.com/'.$row['username'].'" class="username">'.$row['username'].'</a>
'.displayLinks(html_entity_decode($row['text'])).'
</div>
<div class="bottom">
'.displayTimeAgo(strtotime($row['created'])).' via '.$row['source'].'
</div>
</div>';
}
?>