问题
SO i am new at this what i am trying to do is using Angular as Front-end to make a simple button that when clicked asks for user to Authenticate just like any login using gmail example but i keep getting this error and here is my code what i am trying to do is use the code provided by google https://developers.google.com/gmail/api/v1/reference/users/messages/list and covert it to typescript
app.component.ts
export class AppComponent {
async authenticate() {
return await gapi.auth2.getAuthInstance().signIn({
scope: 'https://www.googleapis.com/auth/gmail.readonly',
});
}
app.component.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<script src="https://apis.google.com/js/api.js"></script>
<title>Document</title>
</head>
<body>
<div class="wrapper">
<button class="signup" (click)="authenticate()">authorize and load</button>
</div>
<router-outlet></router-outlet>
</body>
</html>
回答1:
Include this script tag
<script src="https://apis.google.com/js/platform.js"></script>
来源:https://stackoverflow.com/questions/55314208/referenceerror-gapi-is-not-defined