ReferenceError:未定义gapi

时间:2019-03-23 13:29:13

标签: angular typescript gapi

所以我对此很陌生,我想做的是使用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>

1 个答案:

答案 0 :(得分:1)

包括此脚本标记

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