3

I am trying to use Twitters API in order to retrieve a list of hashtagged results - it used to be quite easy because their was no need for authentication but now its become tricky for me...

I have followed this post https://stackoverflow.com/questions/12916539/simplest-php-example-for-retrieving-user-timeline-with-twitter-api-version-1-1/15314662#=

But when i load my page it just displays NULL - i am sure i have done every thing correct

Notice - The PHP file below is in the same directory as the file TwitterAPIExchange

Help would be appreciated thanx

<?php
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "xxxxx",
    'oauth_access_token_secret' => "xxxxx",
    'consumer_key' => "xxxxx",
    'consumer_secret' => "xxxxx"
);

$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=j7mbo';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
                    ->buildOauth($url, $requestMethod)
                    ->performRequest();
var_dump(json_decode($response));
?>
Community
  • 1
  • 1
Hashey100
  • 994
  • 5
  • 22
  • 47
  • 1
    `error_reporting(E_ALL);` – Sammitch Jul 31 '13 at 20:09
  • You might not want to publish your secret tokens – Ross Hambrick Jul 31 '13 at 20:17
  • What HTTP status code are you getting back? There's a chance you are hitting your query limit for the current time frame. But if it never worked then that might not be it. – Ross Hambrick Jul 31 '13 at 20:19
  • 1
    I've removed your tokens. As other's have said, this must be a network / environment issue. Try a new set of keys and see if they work better (usually a "rate limit exceeded" message is returned if you hit it). The next thing you can do is try running this code on another server or a test php online page (like codeviper-7 or equivalent). It works for me and also on my VPS :) – Jimbo Aug 01 '13 at 09:14

2 Answers2

8

Add CURLOPT_SSL_VERIFYPEER => false to the CURL options within the performRequest() method in TwitterAPIExchange.php. That seems to solve it.

cf here

Tom D
  • 104
  • 1
  • 2
2

It works fine for me. My results are here: http://pastebin.com/FB1zpuuT

Start by verifying that you can connect to this in your web browser. https://api.twitter.com/1.1/statuses/user_timeline.json

If you can connect to that, you will see an error message. If not, the problem is likely your network blocking Twitter, or Twitter blocking your ip address.

Terry
  • 989
  • 8
  • 29
  • wierd as hell - when i tried the link in my browser it displayed an error message... but the code still displays NULL for me =/ – Hashey100 Jul 31 '13 at 20:33
  • This is my second PHP application using Twitter API v1.1 and TwitterAPIExchange. The first app works great but I'm experiencing the exact same result as you: `null` is returned. I tried resetting my Consumer Key and Consumer Secret and replacing my keys in my config file but I'm still getting `null`. I am getting the error when I try to connect to @Terry 's link. – Anthony Sep 16 '13 at 23:55