1.1 App authentication, debugging and error code 0


#1

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


#2

Usually when you see HTTP status code “0” it means that your request isn’t reaching the internet (it’s not sent as a response from Twitter itself).

In the environment where you’re having trouble getting this working, consider reviewing what’s different – how is SSL setup on that server? often the issue is that your application code can’t find a valid Open SSL installation to evaluate SSL connections with.


#3

Thanks I’ll ask the hosting guys about this.


#4

@leads: where you able to find a solution for this?


#5

No. My hosts said everything was fine. To be honest I haven’t looked at it again since.
Maybe this weekend.