Shilan
Shilan

Reputation: 833

Google calendar CORS error

I am trying to get json data from google calendar using this jquery piece of code:

var calendar_json_url = "http://www.google.com/calendar/feeds/[email protected]/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>" );
    });
  });

but the problem is that I keep receiving "Cross-Origin Request Blocked" error. I don't want to use default google calendar. I just need the data and want to reformat it in another way! Am I doing something wrong? when I add &callback=? the error doesn't appear anymore, but it doesn't get the data too!

Upvotes: 4

Views: 2970

Answers (1)

Palpatim
Palpatim

Reputation: 9262

The browser security model restricts scripts from accessing data delivered from domains other than the one from which the page was loaded, unless the server enables Cross-Origin Resource Sharing (Read the Spec, or a more readable discussion from Adobe).

It appears Google doesn't enable CORS requests on its feeds. From what I'm seeing, you'll have to register as a developer and use the JavaScript API to make Cross-Origin requests: https://developers.google.com/api-client-library/javascript/dev/dev_jscript#Option3UseCORS

Upvotes: 2

Related Questions