【问题标题】:ReferenceError: gapi is not definedReferenceError:未定义gapi
【发布时间】:2019-08-14 07:14:29
【问题描述】:

所以我是新手,我正在尝试做的是使用 Angular 作为前端来制作一个简单的按钮,单击该按钮时要求用户进行身份验证,就像使用 gmail 示例的任何登录一样,但我不断收到此错误,在这里是我的代码我想做的是使用谷歌提供的代码 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>

【问题讨论】:

  • 您是否包含了 Google 平台 API 脚本?

标签: angular typescript google-api-js-client


【解决方案1】:

包含这个脚本标签

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

【讨论】:

  • 仍然出现同样的错误 core.js:15723 ERROR 错误:未捕获(承诺中):ReferenceError:gapi 未定义参考
  • 你是否包含在 index.html 中
  • 好的,但我提出了一个新的错误 core.js:15723 错误错误:未捕获(承诺中):TypeError:无法读取 null 的属性“signIn”
  • stackoverflow.com/questions/38846232/… 通过这个答案并尝试实施
  • 这是缩小版:&lt;script src='https://apis.google.com/js/api.js'&gt;&lt;/script&gt;
猜你喜欢
  • 2021-10-26
  • 1970-01-01
  • 2021-07-25
  • 1970-01-01
  • 2012-08-24
  • 2019-02-20
  • 1970-01-01
  • 2015-10-04
相关资源
最近更新 更多