- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试通过以下问题使用 angular2 的 google 登录:Google Sign-In for Websites and Angular 2 using Typescript
但是我得到一个错误:
ORIGINAL EXCEPTION: ReferenceError: gapi is not defined
ORIGINAL STACKTRACE:
ReferenceError: gapi is not defined
at LoginAppComponent.ngAfterViewInit (http://localhost:3000/app/login.component.js:33:9)
at DebugAppView._View_AppComponent0.detectChangesInternal (AppComponent.template.js:46:68)
at DebugAppView.AppView.detectChanges (http://localhost:3000/node_modules/@angular/core//bundles/core.umd.js:12143:18)
at DebugAppView.detectChanges (http://localhost:3000/node_modules/@angular/core//bundles/core.umd.js:12247:48)
at DebugAppView.AppView.detectViewChildrenChanges (http://localhost:3000/node_modules/@angular/core//bundles/core.umd.js:12169:23)
at DebugAppView.AppView.detectChangesInternal (http://localhost:3000/node_modules/@angular/core//bundles/core.umd.js:12154:18)
at DebugAppView.AppView.detectChanges (http://localhost:3000/node_modules/@angular/core//bundles/core.umd.js:12143:18)
at DebugAppView.detectChanges (http://localhost:3000/node_modules/@angular/core//bundles/core.umd.js:12247:48)
at ViewRef_.detectChanges (http://localhost:3000/node_modules/@angular/core//bundles/core.umd.js:10397:69)
at eval (http://localhost:3000/node_modules/@angular/core//bundles/core.umd.js:9911:88)
显然 gapi 没有定义 - 我可以理解,因为我似乎只声明了一个空变量。
我目前的代码如下:
import {Component, NgZone} from "@angular/core";
declare var gapi: any;
@Component({
selector: "login",
templateUrl: "templates/login-template.html"
})
export class LoginAppComponent {
googleLoginButtonId = "google-login-button";
userAuthToken = null;
userDisplayName = "empty";
constructor(private _zone: NgZone) {
console.log(this);
}
// Angular hook that allows for interaction with elements inserted by the
// rendering of a view.
ngAfterViewInit() {
// Converts the Google login button stub to an actual button.
gapi.signin2.render(
this.googleLoginButtonId,
{
"onSuccess": this.onGoogleLoginSuccess,
"scope": "profile",
"theme": "dark"
});
}
// Triggered after a user successfully logs in using the Google external
// login provider.
onGoogleLoginSuccess = (loggedInUser) => {
this._zone.run(() => {
this.userAuthToken = loggedInUser.getAuthResponse().id_token;
this.userDisplayName = loggedInUser.getBasicProfile().getName();
});
}
}
模板加载正常,只是 gapi
位。
所以我的问题是:我错过了什么?我需要如何定义 gapi
才能工作?
这是我的主要 app.component 代码:
import { Component } from '@angular/core';
import { LoginAppComponent } from './login.component'
@Component({
selector: 'my-app',
template: `<script src="https://apis.google.com/js/platform.js?onload=onLoadCallback" async defer></script>
<script>
window.onLoadCallback = function(){
gapi.auth2.init({
client_id: 'filler_text_for_client_id.apps.googleusercontent.com'
});
}
</script>
<h1>Angular2 P.O.C.</h1>
<login></login>`,
directives: [LoginAppComponent]
})
export class AppComponent { }
最佳答案
您是否包含了 Google 平台 API 脚本?
<script src="https://apis.google.com/js/platform.js"></script>
参见 this question有关如何在执行代码之前等待 GAPI 脚本加载的说明。
关于javascript - 使用 angular2 和 typescript 进行谷歌登录 - 从哪里获得 gapi?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38664350/
我需要跨多个帐户连接到多个 Google 议程以获取事件。为每个要连接的议程调用以下函数,它适用于第一个查询的帐户,之后我收到上述错误。我怎样才能连接到下一个帐户,身份验证是否需要断开连接或取消设置?
在 Google 的 JavaScript API 中,gapi.load() 和 gapi.client.load() 之间有什么区别?它们之间的互换性如何?我什么时候应该使用其中一个而不是另一个?
我在 Angular 5 中有一个项目,我正在尝试使用 Google gapi.auth2 库实现登录。我被这个错误困住了: ERROR in ./src/app/signin.service.ts
我正在尝试了解如何最好地使用客户端 Javascript 访问 Google 云端硬盘。我写了一些测试代码来插入一个只有元数据的新文件。我找到了一个使用此代码的示例: var request = ga
Exception: GAPI: Failed to request account data. Error: " Error 404 (Not Found)!!1 * {
我根据谷歌文档在页面加载时运行此代码: (function() { var po = document.createElement('script'); po.type = 'text/jav
我很难将 Google javascript api 加载到我的 chrome 扩展程序中。请注意我是 javascript 的新手,甚至是 chrome 扩展的新手。 我有一个执行脚本的 backg
我正在尝试将图像上传到谷歌驱动器。我按照本教程上传文件,我可以上传一个简单的文件,但是当我尝试上传图像时,我得到了损坏的图像。事实上,文件已上传,但我要查看的图像已损坏。我知道问题出在请求的正文中,但
很抱歉,这个话题复活了,但是我也有同样的疑问。 我使用的是gapi,目前“ 2013年10月23日”,谷歌更改了如何获取数据。我无法获得全部访问。 我只需要访问我的网站的总次数,仅此而已。 这是我正在
我正在尝试使用 gapi php 类从分析中获取基本统计信息。我只需要过去 30 天的数据,没有特定维度。这与查看没有分割的分析相同。我从这个开始: $ga->requestReportData($a
我正在使用 GAPI 尝试根据 Google Analytics(分析)数据创建简单的报告。我的内部客户希望看到每页有 2 个字段的概述:综合浏览量和唯一访问者。我的综合浏览量部分可以工作,但我无法让
我做了下面的测试,但是结果不是很好,因为我希望GAPI能有很大的提高。不知道是不是我做错了,希望大家帮我指正,万分感谢! My test environment are OpenCV4.2 offic
从我的 HTML 代码访问 Google+ API 时,我看到了 ReferenceError:gapi is not defined 错误。 我的代码很简单,但不确定它有什么问题。 如有任何意见,我
我正在尝试使用 Google Sheets API 将其包含在我的网络应用程序中,但我一直收到一条错误消息,指出未定义 gapi 库。我尝试使用 ComponentDidMount 生命周期方法延迟对
请遵循以下指示:https://developers.google.com/+/web/api/javascript (function() { var po = document.cr
我目前正在多个位置使用应用调用 gapi.signIn 方法。 当用户登录时 当用户注册时 当用户想要将其应用帐户关联到 Google 帐户时 因此,在每个实例中都会使用不同的回调参数调用 gapi.
我已经投入到一个旨在利用 YouTube API 的小项目中。我已经准备好一些基本代码,我最初认为这些代码可以正常工作。 使用 Chrome,我可以通过我自己网络上的多台机器登录,使用下面的源代码没有
需要在js中进行auth请求,但浏览器不支持弹窗。有什么方法可以重定向到新的 url 或在应用程序的 html5 页面中显示请求 最佳答案 通过使用此代码检查用户是否授权您的应用 gapi.auth.
我有一个基于类的组件,它使用 gapi (Google Auth) API 呈现一个按钮并且它可以工作: import React from 'react'; class GoogleAuth ext
我是 vue 的新手,一直试图在我的网页中包含一个谷歌登录按钮。但是,在我的mounted() 中有一个错误指出“gapi 未定义”。我该如何解决?我也尝试过初始化 gapi,但我不知道该放在哪里。
我是一名优秀的程序员,十分优秀!