Wordpress卷曲谷歌卷曲请求

时间:2014-12-16 02:59:34

标签: wordpress curl google-maps-api-3

我正在尝试使用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/>';
                    }

1 个答案:

答案 0 :(得分:0)

8之前有&key,这可能会导致placeid无效。