WordPress.org

Ready to get started?Download WordPress

Forums

Simply Instagram
[resolved] Fatal error: Cannot use object of type WP_Error as array (15 posts)

  1. karapally
    Member
    Posted 1 year ago #

    I'm getting the error: Fatal error: Cannot use object of type WP_Error as array in /home/kara4190/public_html/wp-content/plugins/simply-instagram/simply-instagram-functions.php on line 187

    I have the Simply Instagram: Recent Media widget in my sidebar.

    Sometimes it loads, and other times I get this error.

    I see some other posts with the same issue. Is there a resolution for this?

    http://wordpress.org/extend/plugins/simply-instagram/

  2. rollybueno
    Member
    Plugin Author

    Posted 1 year ago #

    Hi there,

    This problem occurs because of limited API request to/from Instagram API server. Please use widget caching plugin to solve this temporarily.

    I'm still in developing stage on caching feature.

    Cheers!

  3. Johann Wagner
    Member
    Posted 1 year ago #

    Hi,

    Thanks for indicating WP Widget Cache.

    Got the same error, here's a bugfix for simply-instagram-functions.php line 187

    /**
    * Get the most recent media published by a user.
    */
    function sInstGetRecentMedia( $user_id, $access_token )
    {
    	$apiurl = "https://api.instagram.com/v1/users/" . $user_id . "/media/recent/?access_token=" . $access_token;
    
    	$response = wp_remote_get( $apiurl );
            if(is_array($response) && array_key_exists('body', $response))
            {
                $data = json_decode( $response['body'], true );
                return $data;
            }
            else
            {
                return FALSE;
            }
    }
  4. Orcsik Antal
    Member
    Posted 1 year ago #

    I think there is a better solution for this, according to the wp_remote_get() documentation: http://codex.wordpress.org/Function_API/wp_remote_get#Examples

    $data = array();
    $response = wp_remote_get( $apiurl );
    if (is_wp_error($response)) {
        $data = json_decode( $response['body'], true );
    }
  5. williamgenske
    Member
    Posted 1 year ago #

    I have a similar situation, looks like it may be the same core reason, but not sure:

    Fatal error: Cannot use object of type WP_Error as array in /usr/www/users/xnhhwr/ttp/wp-content/themes/kallyas/admin/framework/class-envato-protected-api.php on line 344

    Any help is greatly appreciated.

    Thank you in advance.

    William

  6. Spencer
    Member
    Posted 1 year ago #

    I'm getting the same error as the original poster. Quite unfortunate. This seems like it would be a really good plugin if it worked :-(

    I tried the fixes mentioned above, but then the plugin doesn't output anything. I got the WP Widget Cache plugin. What should I enter for the number of seconds until it expires? I'm trying different values but to no avail.

  7. esmi
    Forum Moderator
    Posted 1 year ago #

    @Spencer: As per the Forum Welcome, please post your own topic. This one is 3 months old.

  8. Karzin
    Member
    Posted 12 months ago #

    Thank you @Johann Wagner. Your solution worked here

  9. spectrum21
    Member
    Posted 11 months ago #

    Hi All,

    I'm getting the same problem after checking the box onmy tjeme for updates and adding an API I randomly got from Envato. When I try to login to wordpress I receive the following:

    Fatal error: Cannot redeclare class Envato_Protected_API in /home/web7day/public_html/adoptoursoldier.com/wp-content/themes/alterna/envato-wordpress-toolkit-library/class-envato-protected-api.php on line 13

    Can sonebody please help...I need to get into the site, thanks.

    Richard

  10. WPyogi
    Volunteer Moderator
    Posted 11 months ago #

    @Richard - your issue is not related to this plugin at all. Please start your own topic.

  11. spectrum21
    Member
    Posted 11 months ago #

    Hi WPyogi,

    I'm new to this. I searched for "API - cannot declare", and I was sent to this group. I'll look around, thanks for responding.

    Richard

  12. naitg
    Member
    Posted 11 months ago #

    Here is a great article by Yoast and most likely the best approach to checking for an error on $response

    http://yoast.com/wordpress-http-api/

    if ( 200 == $response['response']['code'] ) {
    	$body = $response['body'];
    	$data = json_decode( $response['body'], true );
    }

    However check out the article as it gives other approaches as well =)

  13. Snackmaster
    Member
    Posted 11 months ago #

    Same issue here, cropped up out of the blue and prevented all other widgets from loading.

    WP Widget Cache did not help

    @Johann Wagner Solution did work. Thanks!

  14. dodi hidayatullah
    Member
    Posted 7 months ago #

    maybe the issue in timeout, add this script on plugins :

    function wpdocs_extend_http_response_timeout( $timeout ) {
    	return 30; // seconds default wordpress is 5
    }
    add_filter( 'http_response_timeout', 'wpdocs_http_response_timeout' );

    hope this help...

  15. cippoo
    Member
    Posted 5 months ago #

    @dodi ^

    thanks, that helped me on a different project! Cheers!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic