我正在尝试使用Google API CURL请求在单个帖子页面上显示营业时间。这在wordpress之外工作,但得到了一个" INVALID_REQUEST"在Wordpress中出错。我将以下代码添加到我的content.php页面。当我尝试使用WP_Http类时,我遇到了同样的错误。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
'https://maps.googleapis.com/maps/api/place/details/json?placeid='.get_field('google_place_id').'8&key=AIzaSyBsFOzP0Xg7b1GgK3x09l_isAiLUTWwS2g');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
print_r($result);
$json_a=json_decode($result,true);
$now = $json_a[result][opening_hours][open_now];
if ($now == 1) { print "Currently: Open" . '<br/><br/>'; } else { print "Currently: Closed" . '<br/><br/>'; }
$hours = $json_a[result][opening_hours][weekday_text];
foreach ($hours as $v) {
echo $v . '<br/>';
}
答案 0 :(得分:0)
8
之前有&key
,这可能会导致placeid
无效。