本文介绍了ReferenceError:未定义gapi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我对此很陌生,我想做的就是使用Angular作为前端来制作一个简单的按钮,当单击该按钮时,就像使用gmail示例的任何登录一样,要求用户进行身份验证,但是我一直收到此错误,这里我要执行的代码是使用Google提供的代码吗? https://developers.google.com/gmail/api/v1/参考/用户/消息/列表并将其隐藏为打字稿

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 googlehttps://developers.google.com/gmail/api/v1/reference/users/messages/listand covert it to typescript

app.component.ts

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

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>

这篇关于ReferenceError:未定义gapi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:14