Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have an API link ($content bellow), and I need to display the content fetched from this link in the dashboard. I don't have slightest idea how to do this.

if( !class_exists( 'DevMind_DashboardWidget') ) {
    class DevMind_DashboardWidget {
        function devmind_dashboard_widget() {
            // External Iframe Widget
            echo '<script src="//www.gmodules.com/ig/ifr?url=http://widgets.getclicky.com/igdash/clicky.xml&amp;up_siteName=www.ejobindia.com&amp;up_siteID=100542361&amp;up_siteKey=a16e8cf0a5a195e5&amp;up_resultLimit=10&amp;up_showKeywords=1&amp;up_showEngines=1&amp;up_initalSelection=0-summary&amp;up_showPercent=1&amp;synd=open&amp;w=320&amp;h=250&amp;title=Clicky&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>';

            //$content contains the original xml which I need to transfer into data table 
            $content= 'http://serpbook.com/serp/api/?viewkey=dw8628r&auth=678a498d500a203885191bdd16c70190';
        }

        function devmind_add_dashboard_widget() {
            wp_add_dashboard_widget( 
                'devmind-custom-widget', 
                'Campaign Manager', 
                array( 'DevMind_DashboardWidget', 'devmind_dashboard_widget' ) 
            );
        }       
    }

    add_action( 
        'wp_dashboard_setup', 
            array( 
                'DevMind_DashboardWidget', 
                'devmind_add_dashboard_widget' 
            ) 
        );
}
share|improve this question
    
What type of content is it? How often does it update? What code have you got so far? Doesn't the API documents give you some example code? Have you managed to build a empty dash board widget so far? If yes what code have you got so far? Please give as much information to aid us in answering your question –  Brady Nov 2 '12 at 8:39
    
@Brady It's a seo content and updates continuously. Unfortunately the API contains absolute zero documentation hence I'm completely blank how to proceed any further. I'm not much experienced with wordpress. Yes I can build custom dashboard widget but have no idea how to fetch data from another website using API link. My code goes like this.. –  Pritha Roy Nov 2 '12 at 10:31

1 Answer 1

up vote 0 down vote accepted

First, that echo '<script src="//www.gmodules... seems completely unrelated to the question, isn't it?

Second, that API is for a paid service without a public API, so we cannot answer for their "api answer". Ask their support.

What you are looking for is wp_remote_get. Normally, the response from an API is a Json string. But in the case of this service, the Json seems mal-formed. At least, it is not being decoded by json_decode.

So, as far as WordPress is involved, this is what you need to get that data. How you're going to deal with it is off-topic here, try at StackOverflow.

if( !class_exists( 'DevMind_DashboardWidget') ) 
{
    class DevMind_DashboardWidget 
    {
        function devmind_dashboard_widget() 
        {
            $content= 'http://serpbook.com/serp/api/?viewkey=dw8628r&auth=678a498d500a203885191bdd16c70190';

            $api = wp_remote_get( 
                $content, 
                array( 
                    'timeout' => 120, 
                    'httpversion' => '1.1' 
                ) 
            );

            if ( $api['response']['code'] == '200' )
            {
                // This does not work
                $api_array = json_decode( $api['body'] );   
                echo '<pre>DECODED:<br>' . print_r( $api_array, true ) . '</pre>';

                echo '<pre>ORIGINAL:<br>' . print_r( $api['body'], true ) . '</pre>';
            }
        }

        function devmind_add_dashboard_widget() 
        {
            wp_add_dashboard_widget( 
                'devmind-custom-widget', 
                'Campaign Manager', 
                array( 'DevMind_DashboardWidget', 'devmind_dashboard_widget' ) 
            );
        }       
    }

    add_action( 
        'wp_dashboard_setup', 
        array( 'DevMind_DashboardWidget', 'devmind_add_dashboard_widget' ) 
    );
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.