Authenticating a Twitter Feed for OAuth API V1.1 - Timelines & streams

18 February, 2013 by Tom Elliott

This is comment page 5 for Authenticating a Twitter Feed for OAuth API V1.1 - Timelines & streams »


Creating a Custom jQuery Twitter Feed (API v1.1) »
Creating a Twitter Search & Analytics tool »


376 Comments

  • hakhan says:

    Hi Tom; Thank you for your reply.
    I changed this line like this and wrote the first id of user’s tweets but i just get 20 tweets. any solution ?

    $notweets = 6600842922;
    ——————————————————
    $tweets = $connection->get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=”.$twitteruser.”&since_id=”.$notweets);

  • hakhan says:

    Hi Again Tom; I almost did it, i need your help if it’s possible. I changed code like this, but now i have to change “&page” number manually. Is it possible to do a loop for 16 pages (3200 tweets) in this code ?

    get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=”.$twitteruser.”&count=”.$notweets.”&page=”.$nopage.”&exclude_replies=”.$noreply);

    echo json_encode($tweets);
    ?>

  • Garvit says:

    Hey this is rocking tom . would you please let me know that how to fetch all the tweets related to me …because with this we are able to fetch tweets which has been updated by us…

    thanks in advance

  • Mujeeb says:

    I’m using this example to get the replies on a tweet but return json doesn’t include the replies at all.

    Please help me on this. I’m using this url:
    [link removed]

    Also, if I want to get the replies of a particular tweet then how i’ll do it?
    like sample url: https://twitter.com/MujeebFarooqi/status/459340704356261888

    Thanks,
    Mujeeb.

  • Mujeeb says:

    Hi Tom,
    how you doing?

    dude i want to get the replies of a particular feed like from this page https://twitter.com/MujeebFarooqi/status/459340704356261888
    but i tried alot but not getting the replies from the JSON returned from api. How will i do this? any possible solution?

    Really appreciate your help.

    Thanks,
    mujeeb.

  • sanjoy says:

    $favorites = $twitteroauth->get(“https://api.twitter.com/1.1/favorites/list.json?count=1&screen_name=fiverr”);
    foreach ($favorites as $favorite) {
    echo $favorite->name .”;
    }

    What is the problem this line? I am not access this name value.

  • Matt says:

    Where’s step 3 where you put the code in the HTML to display the tweet in the div?

  • Jitender Nagar says:

    Great Tutorial bro

  • Darren says:

    Hi Tom,

    Thanks very much for this – I am normally pretty good with implementing things like this but for some reason I keep getting a 500 error. I had it working fine on the Authenticating tutorial but not when I set it up to work with twitterfeed.js. It finds my get-tweets.php file but then I get a 500 error. I have tried everything to get it to work and as I say the path to the twitteroauth.php was fine on the original authentication method – it just seems to break when implemented into the JavaScript. I am trying to set this up on a WordPress site so maybe that’s the issue – if you could offer any guidance it would be much appreciated…

    Thanks

    • Tom Elliott says:

      Hi Darren, you should only be getting the 500 error in the authentication script… have you got the PHP authentication working OK on your server and outputting the JSON? You should then be able to add the twitterfeed.js into the footer.php or header.php of your WordPress install and change the path to the authentication script. Hope that helps ๐Ÿ™‚

  • Jack says:

    Hi there, I keep getting this error message:

    {“errors”:[{“message”:”Could not authenticate you”,”code”:32}]}

    But there’s very little documentation online about how to solve it. I was just wondering if you had any thoughts!

    Best,
    Jack

  • Lee Peterson says:

    I randomly get this error: Connection problem. Check file path and www vs non-www in getJSON request. Any ideas what’s causing this?

  • Hiren Kansara says:

    Hi !! I am making a website in asp language. How can I configure twitter feed for that ? I want the twitter to load one after the other in a fading animation.

  • merry says:

    Hi, I want to thanks for the great code. It has been working fine until recently the tweet page is empty and doesn’t load as usual.
    When I check the error log it said:

    [16-May-2014 06:34:12 UTC] PHP Warning: require_once(twitteroauth/twitteroauth.php): failed to open stream: No such file or directory in /data01/c2456538/public_html/twitter/get-tweets1.1.php on line 3

    [16-May-2014 06:34:12 UTC] PHP Fatal error: require_once(): Failed opening required ‘twitteroauth/twitteroauth.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /data01/c2456538/public_html/twitter/get-tweets1.1.php on line 3

    Any idea why because it was fine in the past.

  • Mark says:

    Thanks for the script! I got it successfully setup including cache function -> xxxx-tweets.txt successfully written (83KB)

    The .txt contains the tweets I need.

    Question: How do I output only the latest tweet in php? Just in tweet form. Maybe with clickable links if they exist in a tweet.

    Thanks again for this good piece of code.

  • eric says:

    Hi, thanks for the awesome tut. I have had it working for a couple months now but all of a sudden I started getting this error: Uncaught ReferenceError: exception is not defined twitterfeed.js:115

    Any ideas on how I can fix this? I tried fixing it for an hour or so and can’t seem to figure it out.

    here is a link http://wearerally.com (twitterfeed is at bottom of home page, currently getting the catching tweets message)

    thanks!

    • Tom Elliott says:

      Hey Eric, thanks! There seems to be an issue with your get tweets PHP file – no output and no errors. I’d try turning on friendly PHP errors or checking your logs to see what the issue is with the PHP file

  • Tia says:

    Hey Tom, love your work! If I want to to include tweets from more than one user, how would I go on about this?

  • Artem says:

    Can anyone help with issue:
    How to separate information about tweets, that displays?
    http://tinypic.com/r/9029ld/8
    Unfortunately it is difficult to read it.
    Thanks in advance!

  • juliano@miramar says:

    First of all Thank you for this great post!

    I am having one litlle issue I am receiving back this message :

    {“errors”:[{“message”:”Could not authenticate you”,”code”:12345 bare in mind that’s not the real code but I am not sure if I can supply the code to the public so I ommit but the issue is that it couldn’t authenticate me for some reason unknow by me I appreciate if you can help me !

  • Erictires says:

    I surrender for making these procedure works. I cant run the the program it resulted with ‘Fatal error: Call to undefined function curl_init() in C:xampphtdocstesttwitteroauth.php on line 195;,Sorry i appreciate the tutorial but it wont work for me!!’

    • Tom Elliott says:

      Hi Erictires, from the error it looks like a local issue with your PHP or XAMP install – perhaps lack of cURL support. I would try and test on an online server if possible

  • Svraka says:

    Hi, it looks very prety simple and awesome tutorial but I have a error

    {“errors”:[{“message”:”Could not authenticate you”,”code”:32}]}

    What can be the issue of this problem. I have already updated my keys but it doesn`t help

    plz help

  • Adam says:

    Hi Tom,
    I’m a PHP newbie, so it’s probably a simple mistake on my end, but I’m getting

    Fatal error: Class ‘TwitterOAuth’ not found in /home/afudge/dev.mindymillerofficial.com/twitter_feed/get-tweets.php on line 13

  • Nasir says:

    hi there ,
    i know i sound a bit silly , but i have included the .php file using include/require_once … no trouble there . But it says that cannot find twitterOAuth class @line 13.. I have set the path and still it is not being able to access that class ..
    Thanks and regards

  • Nasir says:

    hi there ,
    i am getting an error of undefined offset on $connection->get() . Also tried to change https to http , cURL is up and running in my machine , confirmed it via phpinfo() … Will appreciate your help .
    BTW .. Nice tutorial ๐Ÿ™‚

  • Bojan says:

    *Hey Tom,

    *big thanks for the work!
    *I have started a course on Tuts+ about tweets and ended up looking for the way how to implement tweets API v1.1
    *Except keys, secret, tokens, username and require_once I didn’t touch anything else
    *Now I am having troubles to see tweet json and all I get on screen is

    Fatal error: Class ‘TwitterOAuth’ not found in /home/bojanarcon/public_html/twitting/get-tweets1.php on line 15

    *When I change:
    require_once(“twitteroauth/twitteroauth/twitteroauth.php”)

    *to the one that looks to me now being the proper:
    require_once(“twitteroauth_master/src/TwitterOAuth.php”); //Path to twitteroauth library

    *I end up getting:
    Warning: require_once(twitteroauth_master/src/TwitterOAuth.php): failed to open stream: No such file or directory in /home/bojanarcon/public_html/twitting/get-tweets1.php on line 4

    Fatal error: require_once(): Failed opening required ‘twitteroauth_master/src/TwitterOAuth.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/bojanarcon/public_html/twitting/get-tweets1.php on line 4

    *I have been now too long on this topic to just give up ๐Ÿ™‚

    • Tom Elliott says:

      Hi Bojan, I think this issue is due to the twitteroauth having recently updated and requiring composer to be setup and installed to work. I’ve updated the article to link to a previous version of the library which can be downloaded from the article (right under ‘Step 2’)

  • us jauhari says:

    Get : {“errors”:[{“message”:”Could not authenticate you”,”code”:32}]}
    ———————————–
    my code ;
    $connection = new TwitterOAuth(‘xxx’,’xxx’,’xxx’,’xxx’);
    $content = $connection->get(“account/verify_credentials”);

    $statues = $connection->get(“https://api.twitter.com/1.1/statuses/show.json?id=2236985726”);
    echo json_encode($statues);
    ————————————
    at the same time, with same key and token, i can retrieve user timeline using api by j7mbo, any idea???

  • Bojan says:

    Hey Tom,
    need help because your tutorial was when it was only twitteroauth/twitteroauth.php and twitteroauth/oauth.php, but now it is different in it https://github.com/abraham/twitteroauth . How would you do it now?

    I don’t know why but I get error such as
    Fatal error: Class ‘TwitterOAuth’ not found in /home/bojanarcon/public_html/test/get-tweets.php on line 14 , and I did reference it to the right place from get-tweets [removed]

    • Tom Elliott says:

      Hi Bojan, thanks for highlighting this issue. The library has indeed updated and requires the user of Composer (a way of standardizing things like loading of classes in PHP from what I understand). As I don’t want to ask everyone reading this article to setup Composer on their servers, I’ve updated the post to include a link to a previous version of the TwitterOAuth library which should work for you.

  • Bryce says:

    I’ve been trying to get this up and running but I keep getting the following as an error message:

    error: Connection problem. Check file path and www vs non-www in getJSON request

    Any ideas of what’s going wrong?

    Thanks!

  • Sudhish says:

    Nice one Tom, this was really helpful. Thanks!

  • mebar says:

    I am new to programming. I was looking at how to extract certain number of twitter feed and came across this page. I followed all the steps and tried running the script, i get error “{“errors”:[{“code”:32,”message”:”Could not authenticate you.”}]}”. I am running this from linux mint. Am I missing something? In your tutorial it says that I have to run this from the server, is the error due to running from my machine? please help.

    Thank you in advance. cheers

  • leon harris says:

    hi Tom,

    thanks for the crystal-clear tutorial. i keep coming back to this when i need to add Twitter feed functionality to sites.

    i have a question though (and i’ve spent a long time looking for this): is there a way to add some pagination to this so i can implement some sort of load more/infinite scroll functionality?

    ps (i’m also using a PHP function to grab instagram #search).

    grateful of any help.

    thanks
    Leon

  • Kev says:

    Hi Tom, I have the feed working however if i navigate to another page before the tweet has loaded I get an error popup, any ideas to stop this happening?

    Thanks

  • Vic says:

    I’m a little confused with how this works. so I made a new php file, and put in the appropriate tokens/values. I also have to download that giant file, but how do I run them or use them? where do I put the giant file in regards to this php file? I basically just want to have a text field and a button, and have the text field be the custom search, and on button click, that search returns a json of tweets ๐Ÿ˜€

  • I will quote Abraham from a recently raised issue on github, mentioning your tutorial here, as it seems like the tut needs some update. ๐Ÿ˜‰

    https://github.com/abraham/twitteroauth/issues/498

    “This isn’t the correct use of the TwitterOAuth API:

    $connection->get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=”.$twitteruser.”&count=”.$notweets);
    It should conform the the examples listed on https://twitteroauth.com which would look like this:

    $connection->get(“statuses/user_timeline”, [“screen_name” => $twitteruser, “count” => $notweets’);”

  • Kamran says:

    Hey,
    I am having a problem. I created the application and am not able to figure out what server is and how to access it? I get an error Bad Data Authentication 215 when executing the python script.

    Big thanks

  • Green Coco says:

    The โ€œtwitteroauth-master.zipโ€ file is missing on hyperlink โ€œdownload the oauth files here. Update 15/01/15โ€.

  • youness says:

    This was helpful. I’m now able to write something simple to keep track of my followers. Thanks