I am trying to retrieve contacts from Google within an Angular 4 Universal app.
But I receive this error message once authentication has been done:
Refused to execute script from https://www.google.com/m8/feeds/contacts/default/full?access_token=TOKEN&alt=json because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
At the moment everything is held in one Component:
import { Component, OnInit } from '@angular/core';
import { Jsonp } from '@angular/http';
@Component({
selector: 'refer-friend',
templateUrl: './referFriend.component.html',
})
export class ContactsComponent implements OnInit {
constructor(private jsonp: Jsonp) { }
ngOnInit(): void {
this.auth();
}
auth() {
gapi.auth.authorize({
'client_id': 'CLIENTID.apps.googleusercontent.com',
'scope': 'https://www.google.com/m8/feeds'
}, () => {
this.fetch(gapi.auth.getToken());
});
}
fetch(token: any) {
this.jsonp.get('https://www.google.com/m8/feeds/contacts/default/full?access_token=' + token.access_token + '&alt=json')
.map(data => {
return data;
})
.subscribe(data => {
console.log(data);
});
}
}
I got the code from this sample which works fine without this error happening. So I can only guess Angular is effecting something....
The Google Contacts API documentation has a link to how the alt tag works. The value 'json' does not indicate that it will return JSONP data. Google returns that MIME type because the data it will give you is not executable.
https://developers.google.com/gdata/docs/2.0/reference
Try using the @angular/http
standard get method instead of Jsonp
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments