I am having trouble connecting to an external API through a custom plugin. Below is the script I am trying. Is this the correct way of doing it? I am receiving response code that says 'API may be invalid' but I am entering the correct API key. I was just wondering if it is something I need to check with the API provider or is there something wrong with my code?
$url = 'http://ift.tt/1ovIYe2';
$options = array(
'apikey' => 'xxxxxxxxxxxxxx',
'var1' => 'test',
'var2' => 'testsdfsd',
'var3' => 'sdfsdfssdf',
);
$response = wp_remote_post($url, $options);
if ( is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response) ) {
$retval = '<pre>'.print_r($response).'</pre>';
return $retval;
}
$results = wp_remote_retrieve_body($response);
$retval = '<div><pre>';
$retval .= print_r($results);
$retval .= '</pre></div>';
return $retval;
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire