Recently, I successfully integrated the gapi client into my Angular 2 application. However, I am now facing an issue where my http object is showing as undefined and I can't seem to figure out why.
Here's the snippet of code that's causing the problem: constructor(private http: Http ) {}
initGmailApi() {
gapi.auth2.getAuthInstance().grantOfflineAccess().then(function(resp) {
console.log(resp);
const auth_code = resp.code;
const body = {'AuthCode': auth_code};
const headers = new Headers();
headers.append('Content-Type', 'application/json');
this.http.post('http://localhost:8080/startgmail', body, headers).subscribe(
(Response) => {
console.log(Response);
}
);
});
}
Essentially, what I'm trying to accomplish here is to request permission from the user to access their Gmail account. Once I receive a response, I want to send some data to my backend server.
The issue arises when I try to use this.http outside of the "then" clause - then the http method works fine but creates another problem where the value of "auth_code" is not recognized.
Any insights on what might be missing in my implementation?