View Full Version : Gaaah!! Why Twitter why?!! (API help!)
motionman95
December 18th, 2009, 08:26 PM
OK...for my other forums I coded a quick script (PHP (cURL) & jQuery). It's a simple PHP script that reaches to my twitter XML file (?count=1) to get my latest tweet, then jQuery/AJAX reads the PHP file. Problem is, that I keep hitting Twitter's maximum request restriction. One thing I've noticed is that when I directly access the feed (from my browser) it displays regardless of whether I've hit the maximum or not. I was wondering if, somehow, using the might and prowess of cURL, I could spoof a direct access. Any tips/ideas?
SO PLEASE, PLEASE, REPLY. Even if it's useless!
motionman95
December 18th, 2009, 10:43 PM
So...no replies? I wonder if that means that everyone here hates me...
TheCanadian
December 19th, 2009, 07:48 AM
Maybe try posting in the server side forum and possibly waiting more than 2 hours before deciding that we hate you. I still like you =)
Also, max footer dimensions are 300x60.
Jeff Wheeler
December 19th, 2009, 09:08 AM
You probably shouldn't be hitting the limit. Caching is generally a good idea.
motionman95
December 19th, 2009, 10:39 AM
Maybe try posting in the server side forum and possibly waiting more than 2 hours before deciding that we hate you. I still like you =)
:love_heart:and :huh: But thanks, I'll try posting it there...
Oh and about my sig, it can't be under the max?
You probably shouldn't be hitting the limit. Caching is generally a good idea.
NOOOO not caching!!! :wt: This probably will mean I'll have to cache it until there's a new tweet...:sombrero: Hello cookies...
Oh, and any mod care to move this to the sever-side forum? No? FINE. *opens mod in a bottle*
Mod: "Yes Motion? What do you desire? Your wish is my command!"
Me: "It would be awesome if you'd move this into the server-side forum."
Mod: *moves thread into server-side forum* "What now do you desire?"
Me: It's fine we shook this place up...:ninja: NINJA STYLE!
And so there is the tale of how the Kirupa forums fell, and well...died.
Jeff Wheeler
December 19th, 2009, 11:01 AM
NOOOO not caching!!! :wt: This probably will mean I'll have to cache it until there's a new tweet...:sombrero: Hello cookies...
Or for, say, 2 minutes. Do it server-side.
Voetsjoeba
December 19th, 2009, 11:17 AM
Moved to server-side.
TheCanadian
December 19th, 2009, 01:39 PM
Oh and about my sig, it can't be under the max?
It sure can, but you're over the height limit by about 100 pixels.
blazes
December 19th, 2009, 01:47 PM
Dude, set up a cron job that runs a simple php script that goes out and get's your latest tweet, and stores it in a file tweet.yml. Have it run every 3 or 4 minutes. Then display it from the file.
Jeff Wheeler
December 19th, 2009, 01:47 PM
Don't do that. Use a proper caching mechanism; don't make a mess of it with flat files and cron.
blazes
December 19th, 2009, 02:31 PM
If all he wants to do is cache 1 tweet, he does not need a "proper caching mechanism".
motionman95
December 19th, 2009, 03:22 PM
I don't really know chron...I've played with it tho. And what I planned to do is to set a cookie (2 mins expiration) with the tweet in it, and if that cookie expires then get the tweet again...but is there a better way?
It sure can, but you're over the height limit by about 100 pixels.
Huh? How? It's pretty small...
blazes
December 19th, 2009, 03:29 PM
Don't put it in a cookie.
Just cache it. 2 minutes of cron googling to set it up, and 3 minutes of copying and pasting your already written code into a new file.
Yeldarb
December 19th, 2009, 05:22 PM
Heck for something this simple no need to even put it on a cron. Just store it in a text file from within your script. Before displaying it check the modification time on the text file and if it's older than a certain age that you choose update it otherwise you include the text file's contents rather than hitting twitter.
Should be like 10 lines of code at most.
http://www.tizag.com/phpT/filewrite.php
and
http://php.net/manual/en/function.filemtime.php
Jeff Wheeler
December 19th, 2009, 05:25 PM
If all he wants to do is cache 1 tweet, he does not need a "proper caching mechanism".
I tend to do things properly, for the future.
blazes
December 19th, 2009, 05:33 PM
That's great for an important or even semi-important system, but caching a single tweet isn't one.
motionman95
December 20th, 2009, 01:56 AM
Actually it's not a "single tweet" it's a bbcode on my forums, meaning more than one member will use it. That's why I originally suggested using cookies to cache it...
simplistik
December 20th, 2009, 10:32 AM
You can only hit twitter roughly every 30 seconds per hour. What I do is create a text document that has json encoded string in it that stores both the date and the tweet(s). I have jquery set a 30 second timeout that first calls the text document to check for the last fetch time, compare it to the current time, if the time is less than 30 seconds it just shows the cached tweet in the json string. If it's over 30 seconds it requests twitter api again, rewrites the file and new time ... and viola.
motionman95
December 20th, 2009, 11:10 AM
You can only hit twitter roughly every 30 seconds per hour. What I do is create a text document that has json encoded string in it that stores both the date and the tweet(s). I have jquery set a 30 second timeout that first calls the text document to check for the last fetch time, compare it to the current time, if the time is less than 30 seconds it just shows the cached tweet in the json string. If it's over 30 seconds it requests twitter api again, rewrites the file and new time ... and viola.
That sounds complicated.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.