Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6729811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:20:04+00:00 2026-05-26T10:20:04+00:00

I am using the following code to retrieve an amount of Tweets from the

  • 0

I am using the following code to retrieve an amount of Tweets from the Twitter API:

$cache_file = "cache/$username-twitter.cache";
$last = filemtime($cache_file);
$now = time();
$interval = $interval * 60; // ten minutes

// Check the cache file age
if ( !$last || (( $now - $last ) > $interval) ) {
    // cache file doesn't exist, or is old, so refresh it

    // Get the data from Twitter JSON API
    //$json = @file_get_contents("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=" . $username . "&count=" . $count, "rb");
    $twitterHandle = fopen("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$username&count=$count", "rb");
    $json  = stream_get_contents($twitterHandle);
    fclose($twitterHandle);

    if($json) {
        // Decode JSON into array
        $data = json_decode($json, true);
        $data = serialize($data);

        // Store the data in a cache
        $cacheHandle = fopen($cache_file, 'w');
        fwrite($cacheHandle, $data);
        fclose($cacheHandle);
    }

}

// read from the cache file with either new data or the old cache
$tweets = @unserialize(file_get_contents($cache_file));

return $tweets;

Of course $username and the other variables inside the fopen request are correct and it produces the correct URL because I get the error:

Warning: fopen(http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Schodemeiss&count=5) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /home/ellexus1/public_html/settings.php on line 187

that ^^ error returns whenever I try and open my page.

Any ideas why this might be? Do I need to use OAuth to even just get my tweets!? Do I have to register my website as somewhere that might get posts?

I’m really not sure why this is happening. My host is JustHost.com, but I’m not sure if that makes any diffrence. All ideas are welcome!

Thanks.

Andrew

PS. This code lies inside a function where username, interval and count are passed in correctly, hence in the error code its created a well formed address.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:20:04+00:00Added an answer on May 26, 2026 at 10:20 am

    Chances are you are getting rate-limited

    400 Bad Request: The request was invalid. An accompanying error
    message will explain why. This is the status code will be returned
    during rate limiting.

    150 requests per hour for non authenticated calls (Based on IP-addressing)

    350 requests per hour for authenticated calls (Based on the authenticated users calls)

    You have to authenticate to avoid these errors popping up.

    And also please use cURL when dealing with twitter. I’ve used file_get_contents and fopen to call the twitter API, and found that it is very unreliable. You would get hit with that every now and then.

    Replace the fopen with

    $ch = curl_init("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$username&count=$count");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $it = curl_exec($ch); //content stored in $it
    curl_close($ch);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code within the JCProperty class to retrieve data from a
I'm using the following code to retrieve emails from my Gmail inbox. def get_mail
I was using the following code to retrieve HTML snippets from a database table
I'm using the following code to retrieve named members from an anonymous type. Is
I'm using the following code to retrieve a message from the database and then
Hello I have the following code to retrieve data from my db using nhibernate
I'm using the following Code with the twitter4J library to retrieve all tweets of
I am using the following code to retrieve the user's phone numbers from the
Right now I am able to retrieve the network status using the following code..
I am retrieving results from twitter using jQuery using the following code: $(document).ready(function(){ var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.