Google日历CORS错误

时间:2014-07-19 23:51:48

标签: jquery json google-calendar-api

我正在尝试使用这段jquery代码从谷歌日历中获取json数据:

var calendar_json_url = "http://www.google.com/calendar/feeds/some-@gmail.com/public/full?orderby=starttime&sortorder=ascending&max-results=3&futureevents=true&alt=json";

  // Get list of upcoming events formatted in JSON
  jQuery.getJSON(calendar_json_url, function(data){

    // Parse and render each event
    jQuery.each(data.feed.entry, function(i, item){

      // Render the event
      jQuery("#gcal-events li").last().after( "<li>" + item.title.$t + "</li>" );
    });
  });

但问题是我一直收到“Cross-Origin Request Blocked”错误。我不想使用默认的谷歌日历。我只需要数据,并希望以另一种方式重新格式化! 难道我做错了什么? 当我添加&amp; callback =?错误不再出现,但它也没有得到数据!

1 个答案:

答案 0 :(得分:1)

浏览器安全模型限制脚本访问从加载页面的域以外的域传送的数据,除非服务器启用跨源资源共享(阅读Spec ,或more readable discussion from Adobe)。

Google似乎没有在其Feed上启用CORS请求。根据我所看到的情况,您必须注册为开发人员并使用JavaScript API发出跨域请求:https://developers.google.com/api-client-library/javascript/dev/dev_jscript#Option3UseCORS