我試圖讓谷歌URL縮短與wp_remote_post()谷歌URL縮短API與wp_remote_post
,但我得到錯誤結果,
我知道如何使用捲曲,但在WordPress捲曲不允許的!
這個資源,API與WordPress:
http://codex.wordpress.org/Function_Reference/wp_remote_post
http://codex.wordpress.org/Function_Reference/wp_remote_retrieve_body
http://codex.wordpress.org/HTTP_API#Other_Arguments
http://codex.wordpress.org/Function_Reference/wp_remote_post#Related
個
這谷歌網址縮短服務API文檔:
https://developers.google.com/url-shortener/v1/getting_started#shorten
這是我的代碼:
function google_url_shrt{
$url = 'http://example-long-url.com/example-long-url'; // long url to short it
$args = array(
"headers" => array("Content-type:application/json"),
"body" => array("longUrl" => $url)
);
$short = wp_remote_post("https://www.googleapis.com/urlshortener/v1/url", $args);
$retrieve = wp_remote_retrieve_body($short);
$response = json_decode($retrieve, true);
echo '<pre>';
print_r($response);
echo '</pre>';
}
我會盡力而且我會告訴你,等我。 – user3492381 2014-10-29 05:25:06
不工作! 尋找這個messsage: 這個API不支持解析表單編碼的輸入。 – user3492381 2014-10-29 05:28:59
根據WordPress文檔,'headers'變量的格式也是錯誤的。我更新了我的答案 - 再試一次。 – Manmaru 2014-10-29 05:42:08