This is comment page 2 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 »
Hi Tom,
Firstly thanks for a great post, really helpful. I’m unfortunately one of the select few getting ‘null’ returned. I only get null on the page and nothing else, any ideas why this may be? I checked the path to the twitteroauth.php file and that looks fine, so I’m not sure what the issue may be.
Adam
Thank you very much for this great explanation and telling me about twitteroauth by @abraham. It works like a charm. I followed the PHP way with:
foreach ($tweets as $item) {
echo $item->text;
}
I’m very impressed at the time you give everybody helping them with their problems. You are pure gold!
XXX Marinka from Amsterdam
I wrote this to replace the date at PHP lev and it almost works but not quite as the breaks i think prevent it from working correctly, so it will only replace some instances not all … Ideas on how this can be fixed hers the func I wrote in an attempt to pull off the date parse trick. try this if you would and see if you can maybe get this to work correctly.
echo date_replace($tweets);
function date_replace($json_arr){
foreach($json_arr as $item){
$obj = stripslashes($item->created_at);
$twe = date(“F j, Y”, strtotime($obj));
//$twe = timesince(strtotime($obj),strtotime($obj));
$out .= str_replace($obj, $twe, json_encode($json_arr));
}
return $out;
}
Maybe some bits of my script will help? http://www.tag-tonic.nl/twitter.class.txt
(I can understand if you don’t want to post this because of the link)
Thanx, for this help…….thanx a lot…………..
Thanks for this, just been able to fix the broken feed on my site in less than 10 minutes!
Awsome, thanks man!!!1one
thank you! since v1.1 required auth for even to fetch tweets from a public timeline, I was going crazy. thankfully I’ve come to found your page.
Fixed the blank screen issues for those users who have it?
Probably have this error
Cannot redeclare class OAuthException in OAuth.php on line 8
Simple rename of class in 13 locations on current document, use search and replace
i used the name OAuthExceptiona,
and hoorah,
get-tweets.php works
Hi,
I am creating an app using javascript and Jquery mobile, will you be able to direct me where I could find oAuth and getting twitter feed example using javascript? and not php.
Thanks
HI
I cant seam to get this to work. could someone have a look at the website and give me some help
Thanks
Thank you!
Thanks for your great script, which works well.
Found a problem, it doesn’t like a twitter user name that starts with a underscrore – e.g. _twitteruser
???
Hi Tom, thanks for Ur tutorial.
I have follow Ur tutorial step by step, but how to use this script in my sidebar.
Yeah, I want to add my latest tweet in my sidebar.
In Twitter API v1.0, i use this script:
Please, help me. Thanks.
Thanks.But i have everything well set and getting ‘null’ on my page.
Hi
Ok so all is working and great scraped. is there a way to use query to switch between tweets and show like the latest 5 of something? if so how is this done?
Thanks again anyone for the help
for me it doesn’t work when I try to get json
var timeline = “http://marti1125.webfactional.com/lineauno/index.php”;
$.getJSON(timeline, function(text){
console.log(text);
});
I love this code. Took me hours to eventually find something that works.
Here’s what I have so far:
http://www.whatnowebsite.co.uk/CustomCode/FacebookApps/WNW-TwitterFeed/Feed.php
The intention is to feed this through to a Facebook Page Tab that I already have setup but for some reason when I put the following:
<a href="url; ?>”>url; ?>
It does not echo on screen.
Any suggestions…?
Also, is it possible to echo line breaks…?
Sorry, that code didn’t echo…
echo $item->url;
Thanks. U really helped my work a lot.
Help! I followed your steps, but when I load get-tweets.php with Firefox or IE9, I only get a white page containing the following line:
“get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=”.$twitteruser.”&count=”.$notweets); echo json_encode($tweets); ?>”
Yes, I made sure that the path to the twitteroauth library was correct. However, I’m loading the files off my hard drive. Do I NEED a web server for this to work?
Okay I updated from PHP Version 4.4.9 to 5.3. It seems to be ok with line 17 now, but now it is giving me this error.
Fatal error: Function name must be a string in /home/vg008web04/51/70/2907051/web/gettweets.php on line 19.
Line 19 looks like this:
$tweets = $connection(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=”.$twitteruser.”&count=”.$notweets);
Thanks!
Hello. When I upload the php to my website all I see is “get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=”.$twitteruser.”&count=”.$notweets); echo json_encode($tweets);?>”
Hi Mary,
You need to make sure your PHP file starts like this <?php rather than the <php start in the code posted here. Hope that helps.
Thanks. I tired that and it didn’t seem to work. I’m using 000webhost and I believe it incorporates php
Of course. Thank you Tom!
First of all thanks for the tutorial. I get the JSON parsed data in my seperate PHP file, but once I want to include it in my html I get an error in console that my URL isn’t allowed by the app settings. Which I think is weird because I get the data in the seperate PHP file, but not in the page which is in the same folder…
Any clue whats going wrong here? I’m out of options.
Tom, first of all. Thanks for this useful information. Appreciate the time and effort you make to get this thing going. At the moment i am trying this stuff out.
– Downloaded that Abraham Zip file
– Copy and pasted your code into the get-tweets.php
– Also registered a new application and pasted the correct keys
I am getting {“errors”:[{“message”:”Could not authenticate you”,”code”:32}]}
I did copy and paste the code 5 times now. It keeps saying. {“errors”:[{“message”:”Could not authenticate you”,”code”:32}]}
What did i do wrong? Do you need more information. Just let me know mate.
Cheers.
Jeroen.
HI Tom,
Thank you so much for posting this – I’m sure I’m missing something really obvious, but I’m just getting this Parse error –
Parse error: syntax error, unexpected ‘$twitteruser’ (T_VARIABLE) in /homepages/7/d347169079/htdocs/get-tweets.php on line 6
link is – http://www.dontforgetdesign.com/get-tweets.php
Any help you can give would be much appreciated.
Thanks.
Owen
Sorry Tom,
I was indeed being a little stupid.
Sorted now.
Classic case of spending too long staring at the screen and not being able to see the obvious!
Owen
thanks man you helped me a lot!
put together a working example ready 2 download.
best regards!
Hi there, have followed your instructions but I am not getting any tweets showing – if you could have a look at my site and assist me in any way it would be much appreciated!
http://tworoxdesign.com/get-tweets1.1.php
Thanks,
Ross
Hi tom I think I found a small glitch in the relative_time func in some cases if you see the date of, examp …
19 mar
21 feb
on your end via the script and then click over to twitter from your own site
twitter has it listed as
18 mar
21 feb
Ideas why this would be?
and why this calc appears to be off with twitters?
and a pos fix?
Anyone else notice this?
Hey Tom,
I am a bit of a PHP/jQuery novice, and got thrown through a loop when the blogger.js twitter feed “plugin” got shut down. I am trying to go through this tutorial, but after I filled in the keys and username on my “get-tweets.php” it’s only displaying the last line of PHP code on that page.
Any help you could provide would be awesome! Thanks.
Hey Tom,
I tried setting up this authentication, downloaded the twitteroauth library and crated a get-tweets.php file with the correct keys input, and uploaded it to my personal site, but when I load the page, all I get is:
get(“https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=”.$twitteruser.”&count=”.$notweets); echo json_encode($tweets); ?>
output on the screen. No error or anything, just no json script showing up.
Any ideas what’s wrong?
Hi Kev, the PHP file is fine but you’re using the old twitter JavaScript code and you need a script that will parse the tweets PHP. Check out my feed integration tutorial: https://tomelliott.com/javascript-ajax/custom-twitter-feed-integration-jquery/
Hi, sorry for my stupdity and thanks for trying to make simple what twitter changed from simple to complex for reasons i cant understand .. but ..
SO this ISNT just a simple drop in and replace for the v1 that blogger.js was using?
My tweets.php file seems to kick out the json fine for the 1 tweet I simply want to display but the blogger.js code isn’t dropping that in.
Clearly im missing something and its simple. Any help please?
Im just after my latest tweet and thats it. Thanks again.
if this helps this is in my footer
and this is the code to display the tweet
function twitterCallback(obj) {
var id = obj[0].user.id;
document.getElementById(‘my_twitter_status’).innerHTML = obj[0].text;
document.getElementById(‘my_twitter_status_time’).innerHTML = obj[0].created_at;
}
still its loading
Thanks for this post, it was really helpful! …I’m just having one issue… I got the twitter feed working no problem on my test server, but when I duplicated it on my client’s server it no longer worked, so I checked the get-tweets.php file and it returned this error:
Parse error: parse error, expecting `T_OLD_FUNCTION’ or `T_FUNCTION’ or `T_VAR’ or `’}” in /users/7/EC3/0CEC37/twitteroauth/twitteroauth.php on line 17
I’m new to PHP so if anyone could help me decipher what it means, it would be greatly appreciated.
Thanks!
Hi Tom,
I got this to work on a test server (bluehost), but now that I’m trying to implement this on one of my work test sites it doesn’t work. I’m including the JS file in this work projects directory JS folder, but in that file, I’m using an absolute path back to the test server (//design.eqalhosting.com/Twitter/Test/get-tweets.php). I checked net tab and am getting no response. Any ideas?? I would like to send you the work test site url privately.
Thanks
I subbed in all of the required keys and tokens but I keep getting this error:
{“errors”:[{“message”:”Timestamp out of bounds”,”code”:135}]}
Do you know what’s wrong? The clock on my computer is correct.
Hello Tom,
I am trying my best to follow your tutorials as a beginner, but it’s extremely hard. I am not a programmer/developer so I am very confused. *sigh*
Anyway, so I added this PHP//
http://pastebin.com/YL3Kq2jU
into a get-tweets1.1.php file.
I uploaded “/twitteroauth” and visited “http://example.com/test/get-tweets1.1.php”
but this error message popped up//
“Fatal error: require_once() [function.require]: Failed opening required ‘twitteroauth/twitteroauth/twitteroauth.php’ (include_path=’.:/usr/local/php52/pear’) in /home/example/public_html/test/get-tweets1.1.php on line 3″
Do you mind explaining what the issue is please?
I’d appreciate it if you can help when you have spare time
Please…
Hi Tom,
Sadly I’m one of the group getting “null” when I test. PHP version is new enough, cURL is installed and appears to play nicely with OpenSSL… any clues? I can email files across if you want, although all I’m actually using is the OAuth.php and twitteroauth.php libraries, plus your get-tweets example. The keys have been copied and pasted from the relevant Twitter dev page, I remembered to update the username… don’t think it can be a migration issue since I’m using your code! Any hints?
Best,
Mel
(That said, making the get-tweets script pull from http://api.twitter.com rather than https:// does actually seem to work…. but so does cURL run from the command line and trying to pull over HTTPS. I wonder if PHP is looking at the wrong version of cURL or something.)
Fixed it. It turned out to be a versioning issue — PHP/Apache were looking at an earlier version of Curl which didn’t have OpenSSL support compiled in.
The quote issue is PHP based not browser based and is dependent on how its been set. I find that on most PHP installs this is a problem and we need to do some form of stripslashes if magicquotes is on.
I think its been removed 5.4 and higher.
Do you have any type of starting point for parsing through the data sent? so i can grab the date.
I will try to see if i can set up some type of regex to parse the date but not to sure. have to think about that one, as i really want that formatted server side as I have done in the past.