ReferenceError: gapi is not defined

2019-08-22 14:08发布

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条回答
做个烂人
2楼-- · 2019-08-22 14:41

Include this script tag

<script src="https://apis.google.com/js/platform.js"></script>
查看更多
登录 后发表回答