Using Twitter API on shared server - speed limit exceeded even if I cache response

I wrote a php script that gets the latest status update for 12 different Twitter accounts, pulling out xml for each and caching it on my server. This is done every 30 minutes.

Unfortunately, I continue to "exceed the bid limit. Customers may not make more than 150 requests per hour." although I only make 24 requests from 150 that I should have.

I guess this is because my domain is on a shared server, and Twitter is counting other requests against me.

How do I resolve my requests so that I am not limited by the standard IP limit?

I have no OAuth experience, so if possible you will need step-by-step instructions.

Thanks in advance!

+3
source share
2 answers

OK, so I managed to get the most out of this work without API experience, etc.

Here is my walkthrough:

Step 1. Create a Twitter List.

  • Go to: https://twitter.com/username/lists
  • Click Create List
  • Enter the data and save.
  • Go to the Twitter user you want to add to the list and click the drop-down list of programs and select "Add or remove from lists." Check the box next to your list.

Step 2. Create a Twitter app via: https://dev.twitter.com/apps/new

  • Log in using your Twitter credentials.
  • Give your application a name, description, etc.
  • "" " ", " Twitter".
  • " " .

, , . .

3. API.

  • Abraham Twitter oAuth : https://github.com/abraham/twitteroauth ( "" ).

  • , authorise.php oAuth ( ). ( <? PHP ? > ).

    // Create our twitter API object
    require_once("twitteroauth/twitteroauth.php");
    $oauth = new TwitterOAuth('Put-Consumer-Key-here', 'Put-Consumer-secret-here', 
    'Put-Access-Token-here', 'Put-Access-token-secret-here');
    // Send an API request to verify credentials
    $credentials = $oauth->get("account/verify_credentials");
    echo "Connected as @" . $credentials->screen_name;
    // Post our new "hello world" status
    $oauth->post('statuses/update', array('status' => "hello world"));
    
  • - API " " Twitter.

. /, , , API, , , . ( , ).

4. PHP, .

  • XML (YOUR-FILE-NAME.xml) oAuth.
  • PHP (YOUR-PHP-FILE.php) oAuth
  • API- twitter, Twitter PHP. ( <? PHP ? > ).

    /* Twitter keys & secrets here */
    $consumer_key = 'INSERT HERE';
    $consumer_secret = 'INSERT HERE';
    $access_token = 'INSERT HERE';
    $access_token_secret = 'INSERT HERE';
    
    // Create Twitter API object
    require_once('twitteroauth/twitteroauth.php');
    // get access token and secret from Twitter
    $oauth = new TwitterOAuth($consumer_key, $consumer_secret, $access_token,                 $access_token_secret);
    // fake a user agent to have higher rate limit
    $oauth->useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9';
    
    // Send an API request to verify credentials
    $credentials = $oauth->get('account/verify_credentials');
    echo 'Connected as @' . $credentials->screen_name . '\n';
    
    // Show API hits remaining
    $remaining = $oauth->get('account/rate_limit_status');
    echo "Current API hits remaining: {$remaining->remaining_hits}.\n";
    
    $ch = curl_init();
    $file = fopen("YOUR-FILE-NAME.xml", "w+");
    curl_setopt($ch, CURLOPT_URL,'https://api.twitter.com/1/lists/statuses.xml?slug=INSERT-LIST-NAME&owner_screen_name=INSERT-YOUR-TWITTER-USERNAME-HERE&include_entities=true');
    curl_setopt($ch, CURLOPT_FILE, $file);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($file);?>
    
  • . (, http://www.yourwebsite.com/twitter/YOUR-PHP-FILE.php)

twitter, XMl YOUR-FILE-NAME.xml. , XML, .

5. PHP script , ( 350 ) Cron.

  • Cpanel "Cron jobs" ( "" ).
  • script, .
  • :

    php/home/CPANEL-USERNAME/public_html/WEBSITE/twitter/YOUR-PHP-FILE.php > /dev/null 2 > & 1

script , , YOUR-FILE-NAME.xml.

6. XML , , API.

, , - ?

+3

a) 12 , [] https://twitter.com/lists = > 12

b) oAuth lib: https://github.com/abraham/twitteroauth oAuth- unsigned = > 350 , IP

+2

All Articles