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

  • SEARCH
  • Home
  • 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 7874933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:53:50+00:00 2026-06-03T02:53:50+00:00

All, I have the following code to retrieve some Tweets: if( ! $tweet )

  • 0

All,
I have the following code to retrieve some Tweets:

if( ! $tweet ) {
    $url = "http://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$how_many}";
    $curl = curl_init();
    curl_setopt( $curl, CURLOPT_URL, $url );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
    $contents = curl_exec( $curl );
    curl_close( $curl );
    if ( ! empty( $contents ) ) {
        // Decode it.
        $tweet = json_decode( $contents );
        }
    }

    // Check to make sure we have a tweet and display it.
    if ( $tweet ) {
        do_action( 'themeblvd_twitter_slider', $tweet, $options, $username, $slider_id );
    } else {
        $output = 'Twitter timed out.';
    }
    return $output;

I then have the following code to put them in a Slider:

function themeblvd_twitter_slider_default( $tweet, $options, $username, $slider_id ) {
$tweet = (array)$tweet;
$classes = themeblvd_get_classes( 'slider_standard', true );
$classes .= ' hide-nav_standard';
$classes .= ' show-nav_arrows';
$classes .= ' show-pause_play';

//themeblvd_twitter_slider_js( $slider_id, $options );
?>
<div id="tb-slider-<?php echo $slider_id; ?>" class="slider-wrapper standard-slider-wrapper">
    <div class="slider-inner<?php echo $classes; ?>">   
        <div class="slides-wrapper slides-wrapper-<?php echo $slider_id; ?>">
            <div class="slides-inner">
                <div class="slider standard-slider flexslider">
                    <div class="tb-loader"></div>
                    <ul class="slides">
                                <?php
                                foreach($tweet as $t){
                                ?>
                                <li class="slide tight <?php echo $classes; ?>">
                                    <div class="slide-body">
                                        <div class="grid-protection">
                                        <?php
                                        echo '<span class="tweet-icon '.$options['icon'].'"></span>';
                                        echo '<a href="http://twitter.com/'.$username.'/status/'.$t->id_str.'" target="_blank">';
                                        echo $t->text;
                                        echo '</a>';
                                        ?>

                                        </div><!-- .grid-protection (end) -->
                                    </div><!-- .slide-body (end) -->
                                </li>
                                <?php
                                }
                                ?>
                    </ul>
                </div><!-- .slider (end) -->
            </div><!-- .slides-inner (end) -->                  
        </div><!-- .slides-wrapper (end) -->
    </div><!-- .slider-inner (end) -->
    <div class="design-1"></div>
    <div class="design-2"></div>
    <div class="design-3"></div>
    <div class="design-4"></div>                    
</div><!-- .slider-wrapper (end) -->
<?php
}
?>

This code works about 90% of the time and grabs the tweets based on a username etc. However, about 10% of the time it just rotates without displaying any of the texts. Does anyone see anything or a way that I can make this solution better so that the tweets are always displayed? Is there anything from an error handling perspective that I’m missing that I could add to not display it if it can’t retrieve the tweets?

Thanks for any advice in advance.

  • 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-06-03T02:53:51+00:00Added an answer on June 3, 2026 at 2:53 am

    You could try to check if what twitter returns actually is a list of tweets. At the moment you only check if twitter returns anything at all.

    // Check to make sure we have a tweet and display it.
    if ( is_array($tweet) && isset($tweet[0]->id_str) ) {
        do_action( 'themeblvd_twitter_slider', $tweet, $options, $username, $slider_id );
    } else {
        $output = 'Twitter timed out.';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: query = Entry.objects.all() print 'authors ' + repr([x.id for
I have the following code to assign a value to all the elements of
I have this following code which will return all the current semesters. How do
I have the following code: class MyClass def method foo = MyClass.all end end
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
I have a following code , I want to display all the attributes of
So I have the following code for fetching all of my core data entities
I have the following code: Tag.find_all_by_company_id(4).each.collect{|tag| tag.name }.join(,) (Essentially I'm trying to build a
I have the following code: preg_match_all('/(.*) \((\d+)\) - ([\d\.\d]+)[,?]/U', E-Book What I Didn't Learn
I have the following code which uploads images to a rackspace cdn account. error_reporting(E_ALL);

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.