ReferenceError: gapi is not defined

风格不统一 提交于 2019-12-13 03:49:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!