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>
1
  • Have you included the Google platform API script? Commented Mar 23, 2019 at 14:08

1 Answer 1

10

Include this script tag

<script src="https://apis.google.com/js/platform.js"></script>
Sign up to request clarification or add additional context in comments.

5 Comments

still getting the same error core.js:15723 ERROR Error: Uncaught (in promise): ReferenceError: gapi is not defined Refe
Did you include in index.html
ok it worked but i raised a new error core.js:15723 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'signIn' of null
stackoverflow.com/questions/38846232/… go through this answer and try to implement
This has the minified version: <script src='https://apis.google.com/js/api.js'></script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.