我花了几个小时试图研究和解决这个问题,但不幸的是,我仍然在挣扎。
我已经创建了一个自定义的‘课程’文章类型在Wordpress,其中涉及使用嵌入式Calendly事件注册。当事件注册发生时,我正在使用Calendly到通知父窗口。通知有效负载提供事件的URI,然后使用Calendly查找该事件,并返回事件的名称。我很难将API密钥隐藏在标题中:
"Content-Type": "application/json",
"Authorization": "Bearer MY_API_KEY"
}我尝试在wpconfig中添加一行来定义键:
define( 'CALENDLY_KEY', '**key**' );但我不知道如何在我的函数中使用它,而不通过“echo”公开它。
如有任何建议,将不胜感激。
扩展代码如下:
<!-- Calendly widget script -->
<script type="text/javascript" src="https://assets.calendly.com/assets/external/widget.js" async></script>
<script>function isCalendlyEvent(e) {
return e.data.event &&
e.data.event.indexOf('calendly') === 0;
};
window.addEventListener(
'message',
function(e) {
if (isCalendlyEvent(e)) {
if (e.data.event == "calendly.event_scheduled") {
console.log("event scheduled!");
let event_uri = e.data.payload.event.uri;
console.log(event_uri);
fetch(event_uri, {
"method": "GET",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer MY_API_KEY"
}
})
.then(response => response.json())
.then((json) => {
console.log(json);
let ordered_course = json.resource.name;
console.log(ordered_course);
})
}
console.log(e.data);
}
}
);</script>发布于 2022-01-21 22:32:20
https://stackoverflow.com/questions/70785007
复制相似问题