ReferenceError: gapi is not defined

ReferenceError: gapi is not defined

所以我是新手,我正在尝试做的是使用 Angular 作为前端来制作一个简单的按钮,单击该按钮时要求用户进行身份验证,就像使用 gmail 示例的任何登录一样,但我不断收到此错误,这是我的代码,我想做的是使用 google 提供的代码 https://developers.google.com/gmail/api/v1/reference/users/messages/list 并将其转换为打字稿

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>

包括这个脚本标签

<script src="https://apis.google.com/js/platform.js"></script>