First, that echo '<script src="https://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' )
);
}