【发布时间】:2018-12-12 14:42:34
【问题描述】:
我正在尝试通过 Groove 的 JSON API 获取数据。
https://www.groovehq.com/docs/tickets#listing-tickets 和https://www.groovehq.com/docs
这是我制作的代码:
<?php
function timjson_front($atts, $content) {
global $wpdb;
$access_token = ""; //insert token
$user_email = ""; // insert customers email
$json = getJSON($access_token, $user_email);
$html = "";
foreach($json as $key => $waarde) {
$html .= $key . ' = ' . $waarde;
}
return html_entity_decode($html);
}
function getJSON($access_token, $user_email) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://api.groovehq.com/v1/tickets?acces_token=' . $access_token . '&customer=' . $user_email);
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
return $obj;
}
?>
代码在 wordpress 页面上运行,是自制插件的一部分。这个想法是将客户的票打印在页面上。
Wordpress 在foreach() 给出错误。有谁知道我做错了什么?或者有什么建议?
【问题讨论】: