ReferenceError: gapi is not defined
Asked Answered
T

1

0

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>
Tojo answered 23/3, 2019 at 13:29 Comment(1)
Have you included the Google platform API script?Wexford
W
10

Include this script tag

<script src="https://apis.google.com/js/platform.js"></script>
Wexford answered 23/3, 2019 at 14:14 Comment(5)
still getting the same error core.js:15723 ERROR Error: Uncaught (in promise): ReferenceError: gapi is not defined RefeTojo
Did you include in index.htmlWexford
ok it worked but i raised a new error core.js:15723 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'signIn' of nullTojo
#38846732 go through this answer and try to implementWexford
This has the minified version: <script src='https://apis.google.com/js/api.js'></script>Chamaeleon

© 2022 - 2024 — McMap. All rights reserved.