- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试将 Google Analytics Core Reporting API 与 JavaScript 一起使用。
我是新手,我试图使用谷歌提供的示例代码 core_reporting_api_v3 .
但是在 core_reporting_api_v3.html
之后文件运行它调用 auth_util.js
.
来自 auth_utils.js 的代码:
function checkAuth()
{
gapi.auth.authorize({client_id: clientId, scope: scopes}, handleAuthResult);
}
function handleAuthResult(authResult)
{
alert("made it");
if (authResult)
{
gapi.client.load('analytics', 'v3', handleAuthorized);
}
else
{
handleUnAuthorized();
}
checkAuth()
函数调用 google api
gapi.auth.authorize
带有客户端 ID、范围、立即数(已尝试:true/false)和回调函数。它应该会弹出一个授权窗口进行用户授权。之后调用回调函数。
gapi.auth.authorize
在javascript中以原始形式作为REST API调用?
最佳答案
我有一个类似的问题,所以修改了样本以适应。包含的顺序似乎也影响了它。
这对我有用:
<script language="javascript">
// PURPOSE: Load in ClientID and API key dynamically
var cMsg;
var cStatus = '';
var clientId = '<?php echo $authClientID; ?>';
var apiKey = '<?php echo $authDevKey; ?>';
var scopes = 'https://www.googleapis.com/auth/analytics.readonly';
var scope = 'https://www.google.com/analytics/feeds';
var profileId = '';
</script>
<!-- CORE API JS -->
<script src="js/hello_analytics_api_v3_auth.js"></script>
<script src="js/hello_analytics_api_v3.js"></script>
<!-- Load the Client Library. Use the onload parameter to specify a callback function -->
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
Here is the code i've used to get around it Saved in hello_analytics_api_v3_auth.js:
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
}
// 3. Check if the user has Authenticated and Authorized
function checkAuth() {
// Call the Google Accounts Service to determine the current user's auth status.
// Pass the response to the handleAuthResult callback function
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
}
// 4. Update the UI based on the user's authorization status
function handleAuthResult(authResult) {
if (authResult) {
// The user has authorized access
// Load the Analytics Client. This function is defined in the next section.
loadAnalyticsClient();
} else {
// User has not Authenticated and Authorized
handleUnAuthorized();
}
}
// 3. Create An Analytics Service Object
function loadAnalyticsClient() {
// Load the Analytics client and set handleAuthorized as the callback function
gapi.client.load('analytics', 'v3', handleAuthorized);
}
关于javascript - 对于 javascript,对 api "gapi.auth.authorize"的调用未执行谷歌分析。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10947191/
我需要跨多个帐户连接到多个 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,但我不知道该放在哪里。
我是一名优秀的程序员,十分优秀!