jQuery JSONP ajax, authentication header not being set

I had the same problem recently. Try this:

$.ajax({
  url: "https://www-opensocial.googleusercontent.com/api/people/@me/@all",
  dataType: 'jsonp',
  data: {
    alt: 'json-in-script'
  },
  success: function(data, status) {
    return console.log("The returned data", data);
  },
  beforeSend: function(xhr, settings) { xhr.setRequestHeader('Authorization','Bearer ' + token); } 
});

EDIT: Looks like it can’t be done with JSONP. Modify HTTP Headers for a JSONP request

Leave a Comment