gpt4 book ai didi

javascript - 如何在新的 Google Calendar v3 API 结果上使用 PHP 的 'json_decode'?

转载 作者:行者123 更新时间:2023-12-03 10:32:20 24 4
gpt4 key购买 nike

这是我的代码:

$gcal_path = "https://www.googleapis.com/calendar/v3/calendars/".$gcal_url_encoded_id."/events?maxResults=".$max_Results."&orderBy=startTime&singleEvents=true&timeMax=".$time_Max."&timeMin=".$time_Min."&key=".$api_key;

$feed = json_decode(html_entity_decode(trim(file_get_contents($gcal_path))));

我的脚本中已经准备好了所有其他内容,包括解析 json_decode 中的数据。问题是$feed不包含任何数据。

但是,我已经测试了 $gcal_path变量/链接与 AJAX 解析的 JavaScript 实现(例如 xmlhttp.open("GET","<?php echo $gcal_path ?>",true); 。它会输出所有正确的 JSON 数据。

那么,为什么 PHP 变量为空?我做错了什么?

额外信息:另外,在结果中我注意到了这个 "etag": "\"1576214503014905\"" (出于安全目的,该号码已更改)。

如何处理那些转义的引号,它是否会不可避免地影响 json_decode 的结果函数调用,和 $feed

请帮忙。

最佳答案

解决了!

这是工作代码:

$gcal_path = "https://www.googleapis.com/calendar/v3/calendars/".$gcal_url_encoded_id."/events?maxResults=".$max_Results."&orderBy=startTime&singleEvents=true&timeMax=".$time_Max."&timeMin=".$time_Min."&key=".$api_key;

// Get cURL resource.
$curl = curl_init();

// Set some options - we are passing in a user-agent too here.
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $gcal_path,
CURLOPT_USERAGENT => '{enter a user-agent string ( some can be found at: http://www.useragentstring.com/pages/Chrome/) here, without the curly braces} ',
CURLOPT_REFERER => '{enter the referrer URL, that is allowed to get the calendar JSON, here, without the curly braces}'
));
// Send the request & save response to $resp.
$resp = curl_exec($curl);
// Close request to clear up some resources.
curl_close($curl);

// Populate the '$feed' variable with decoded JSON data.
$feed = json_decode($resp);

感谢@SGC 为我指明了正确的方向!

非常感谢您!

关于javascript - 如何在新的 Google Calendar v3 API 结果上使用 PHP 的 'json_decode'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29153858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com