从公开的Google日历中获取JSON

Rik*_*ard 19 php json google-calendar-api

我怎样才能得到一个JSON与事件的公共谷歌日历?我有它,ID但没有接受它.我不想改变它的事件,也不想登录.

我想JSON从它获得一个与我PHP/ MySql数据库同步.

试着 https://www.googleapis.com/calendar/v3/calendars/{calendarId}

但是登录错误:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}
Run Code Online (Sandbox Code Playgroud)

Tir*_*rno 51

自2014年11月17日起,Google Calendar API的v1和v2已被停用.

Google Calendar API V3几乎需要对所有操作进行oauth身份验证.尽管我可以说,这也需要用户互动.

但是,对于公共日历,仍然可以使用单个链接来获取JSON数据(目前Google尚未对此进行记录 - 我不知道它们是对自己的疏忽还是明天可能会消失的私有API).

  1. 使用Google Developers Console注册您的应用程序
  2. 在Google Developers Console中激活Google Calendar API.
  3. 凭据下,创建一个新的公共API访问密钥(您可能希望将引用空白留待测试)
  4. JSON网址现在看起来像这样

    https://www.googleapis.com/calendar/v3/calendars/ {calendarid}/events?key = {您的公共API密钥}

(花括号{}不应出现在实际的URL中).

API文档描述了您可以包含的其他参数(除了您还可以包含参数&callback =,与大多数JSON请求一样,为javascript创建JSONP响应).


Lak*_*aky 8

您的日历必须公开分享! 如果您只共享空闲/忙碌状态,则此工作正常:

http://www.google.com/calendar/feeds/{calendarId}@group.calendar.google.com/public/basic?orderby=starttime&sortorder=ascending&futureevents=true&alt=json
Run Code Online (Sandbox Code Playgroud)

详细信息 - 仅当日历完全公开共享时才会显示此信息

http://www.google.com/calendar/feeds/{calendarId}@group.calendar.google.com/public/full?orderby=starttime&sortorder=ascending&futureevents=true&alt=json
Run Code Online (Sandbox Code Playgroud)

或者只是自由忙碌

http://www.google.com/calendar/feeds/{calendarId}@group.calendar.google.com/public/free-busy?orderby=starttime&sortorder=ascending&futureevents=true&alt=json
Run Code Online (Sandbox Code Playgroud)

参数orderby,sortorderfutureevents是可选的,但可能会帮助你以后:)

  • 自2014年11月以来,免费繁忙链接无效.要获得开始和结束时间,您必须使用下面描述的Google Calendar API V3. (2认同)