WordPress.org

Forums

Kebo Twitter Feed
[resolved] Error with PHP? (18 posts)

  1. pdaniel
    Member
    Posted 1 year ago #

    New to WordPress and PHP so I apologize if this is an easy one. Tried to implement the Kebo twitter into my html document with the following code and I got the below error message:

    <div class="content-wrap">
    <?php $tweets = kebo_twitter_get_tweets(); ?>
    <?php $i = 0; ?>
    <?php foreach ($tweets as $tweet) : ?>
    <?php echo $tweet->text; ?>
    <?php if ( ++$i == 10 ) break; ?>
    <?php endforeach; ?>
    </div>

    Warning: Invalid argument supplied for foreach() in D:\Hosting\2780066\html\wp-content\themes\rapscallion\footer.php on line 41

    Any help would be appreciated!
    Thanks.

    http://wordpress.org/plugins/kebo-twitter-feed/

  2. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    Hi pdaniel,

    It is great to see that you are customising how the Tweets display on your website.

    Looking at your code it does not look there are any PHP problems. It appears that there is nothing in the $tweets variable. I will be updating the example code in the readme with improved code which checks if there is anything in $tweets first. Here is the code:

    <?php $tweets = kebo_twitter_get_tweets(); ?>
    
    <?php $i = 0; ?>
    
    <?php if (is_array($tweets)) : ?>
    
        <?php foreach ($tweets as $tweet) : ?>
    
            <?php echo $tweet->text; ?>
    
            <?php if (++$i == 10) break; ?>
    
        <?php endforeach; ?>
    
    <?php else : ?>
    
        <p>Sorry, no Tweets found.</p>
    
    <?php endif; ?>

    The other problem is why are there no Tweets? If you look at the plugin options page under Settings -> Kebo Twitter, are there any messages displayed in the error log?

    Another thing to check, if you assign the Kebo Twitter Widget to a widget area, does it manage to display the Tweets?

  3. pdaniel
    Member
    Posted 1 year ago #

    I don't see any error messages from the settings page. It looks like I'm connected and no error messages in the log. I'll try to add it to the widget area and see if that works. Thanks for the prompt response!

    To enable us to display your Tweets you must connect your Twitter account to our Twitter Application by clicking on the large 'Connect to Twitter' button below.
    Connected to Twitter

    Connected as @rapscallionbeer ✖

    General Options

    Feed Refresh Rate

    Minutes. Should be between 1 and 30.
    This controls how frequently we update the stored list of Tweets for display on your website.

    Error Log

    There is a chance that we may receive errors when making requests to Twitter, which will be displayed below. If errors are occuring consistently please check the key below to see if action is required.
    Date Code Message
    Good news, there have been no errors received from Twitter recently.

  4. pdaniel
    Member
    Posted 1 year ago #

    I don't see how I can add a widget to the page. I have activated the Kebo widget by moving the widget to the right side bar on the Widget page. What would be the next step?

    thanks.

  5. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    Hi pdaniel,

    That should do it, once the widget is in the right side bar area on the Widgets page, it should now be displaying on your website.

    If the widget is set to Style List, it should display on your website either a list of tweets or a message stating 'Sorry, no Tweets were found.' do either of these happen?

    It seems the Plugin and Widget are correctly setup, so it should be displying Tweets on your website. Is that happening?

  6. pdaniel
    Member
    Posted 1 year ago #

    it is set to style: list.

    Here are the settings I have. I don't see it on the web site. The site is customized some so I'm not sure if that has to do with anything.

    Kebo Twitter Feed:

    Title: Latest Tweet
    Style: List
    Theme: Light
    Number Of Tweets: 1

  7. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    And still no luck displaying? Okay...

    Then it suggests to me, it has never managed to get your Tweets.

    I just checked the error log from my script which handles the OAuth requests and there have been 0 errors in the last 24 hours. It might be possible that your install has not actually made a request.

    We can test this by checking what is inside $tweets, where you were trying your custom code could you please try this code:

    <?php $tweets = kebo_twitter_get_tweets(); ?>
    
    <?php print_r($tweets); ?>

    ** note: If this is a production/live site, you might not want to do this as it could output a huge amount of text onto the page, containing masses of Tweet data. **

    Then have a look at the site and see what it outputs? If it outputs anything can you paste that back here please?

  8. pdaniel
    Member
    Posted 1 year ago #

    thanks. It is a live site unfortunately. I can try it later tonight. I'll follow up after to let you know what I find. thanks again!

  9. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    Ah no problem, you could also use a check for an administrator user, and only output it then (for your eyes only!). This code should do it:

    <?php
    // Check for an Admin user, then output $tweets
    if ( current_user_can('activate_plugins') ) {
        $tweets = kebo_twitter_get_tweets();
        print_r($tweets);
    }
    ?>
  10. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    Hi pdaniel,

    Did you have any luck outputting the Tweets? If not can I help troubleshoot the reason in any way?

  11. pdaniel
    Member
    Posted 1 year ago #

    no, my computer was giving me fits last night. going to try today real quick. will let you know. thanks so much for the help.

  12. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    Hi pdaniel,

    I will close this as I haven't heard anything back from you. Just let me know if you still need help, or have any other problems.

    I believe the problem which was causing this has been resolved. I was sending GZIP'd data to all sites, without checking if they had the ability to inflate it once received. I now check for the relevant Accept-Encoding headers and responsd using GZIP if it is supported.

  13. pdaniel
    Member
    Posted 1 year ago #

    Hi Peter - Actually this was on my list to get down. Let me give it another shot tonight based on your feedback and I'll get back to you.

    thanks!

  14. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    Hi pdaniel,

    No problem, ill keep an eye out.

  15. pdaniel
    Member
    Posted 1 year ago #

    Ok, it looks like I was able to pull back tweets when I added the code from your suggestion above. So, I then tried to code the custom tweet per the sample and I got the same error I did before..

    Warning: Invalid argument supplied for foreach() in D:\Hosting\2780066\html\wp-content\themes\rapscallion\footer.php on line 41

    Here's the code..

    <div class="content-wrap">
    <?php $tweets = kebo_twitter_get_tweets(); ?>
    <?php $i = 0; ?>
    <?php foreach ($tweets as $tweet) : ?>
    <?php echo $tweet->text; ?>
    <?php if ( ++$i == 10 ) break; ?>
    <?php endforeach; ?>
    </div>

    Any suggestions? PHP is not my strong point.

    thanks!

  16. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    Hi pdaniel,

    Would you be able to install this version of the plugin please: http://peterbooker.com/kebo/kebo-twitter-feed.zip

    It will send me an email with the contents of the tweet data at two points: 1) when it first fetches it from the API and 2) when it trys to render the widget.

    This will help me to track down what is going wrong with the process. Once it is installed refresh the page a few times with the widget up and I will post back here with what I found out from the emails.

  17. pdaniel
    Member
    Posted 1 year ago #

    Ok, I'll give it a shot. For kicks I plugged in the following code and the else part came back which tells me the data coming back is not in array form maybe?? I checked again with the $tweets = kebo_twitter_get_tweets();
    print_r($tweets);

    and the tweets are coming back ok. I see them fine.

    code:
    <?php $tweets = kebo_twitter_get_tweets(); ?>

    <?php $i = 0; ?>

    <?php if (is_array($tweets)) : ?>

    <?php foreach ($tweets as $tweet) : ?>

    <?php echo $tweet->text; ?>

    <?php if (++$i == 10) break; ?>

    <?php endforeach; ?>

    <?php else : ?>

    <p>Sorry, no Tweets found.</p>

    <?php endif; ?>

  18. Peter Booker
    Member
    Plugin Author

    Posted 1 year ago #

    Hi pdaniel,

    Thanks for coming back to us. The other problems like this have been character encoding issues and the data gets cut off at the bad character, so that when it comes to using it, it is not decoded properly and is not a properly formed array.

    If you can install the above version of the plugin I mentioned above, it will let me see the data directly and I can see if it is the above problem or if there is another issue we need to fix.

    I really appreciate you taking the time to help us debug this issue, it really helps us to improve the plugin, thanks again!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Kebo Twitter Feed
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic