Hi, I am sure this is a question that is a million times but here is another one.
I have a simple user_timeline app to get latest tweets. I know, I know, there are embedded timeline things but I’m just trying to learn some stuff.
I used this tutorial http://wickedlysmart.com/twitternews-oauth/ which uses PHP, the tmhOAuth library and JavaScript.
Works fine locally but not on a domain.
<?php
require ‘app_tokens.php’;
require ‘tmhOAuth-master/tmhOAuth.php’;
$query = htmlspecialchars($_GET[‘query’]);
if (empty($query)) {
$query = “html5”;
}
$connection = new tmhOAuth(array(
‘consumer_key’ => $consumer_key,
‘consumer_secret’ => $consumer_secret,
‘user_token’ => $user_token,
‘user_secret’ => $user_secret
));
// Get the timeline with the Twitter API
$http_code = $connection->request(‘GET’,
$connection->url(‘1.1/statuses/user_timeline’),
array(‘screen_name’ => ‘USERNAME’, ‘count’ => 2, ‘lang’ => ‘en’));
// Request was successful
if ($http_code == 200) {
// Extract the tweets from the API response
$response = json_decode($connection->response[‘response’],true);
$tweet_data = $response;
// Accumulate tweets from results
$tweet_stream = '[';
foreach ($tweet_data as $tweet) {
// Add this tweet's text to the results
$tweet_stream .= ' { "tweet": ' . json_encode($tweet['text']) . ', "created_at" : ' . json_encode($tweet['created_at']) . ' },';
}
$tweet_stream = substr($tweet_stream, 0, -1);
$tweet_stream .= ']';
// Send the tweets back to the Ajax request
print $tweet_stream;
}
// Handle errors from API request
else {
echo $http_code;
if ($http_code == 429) {
print 'Error: Twitter API rate limit reached';
}
else {
print 'Error: Twitter was not able to process that request';
}
}
?>
This works fine locally (localhost), but on a ‘proper’ domain (the same domain as set in the app settings), I get the error at the very end of the code. I echo’d the http_code and it returns a zero (0). I am certain the consumer key, token etc are correct.
I’m a php noob so I’m a little stumped as to what to do next to figure this out. I’d be happy to share more code or whatever if necessary.
Thanks
Tom