我试图使用gapi来上传图片到谷歌云存储.目前的代码,我是
<script src="https://apis.google.com/js/api.js"></script>
<script type="text/javascript">
var imgData = null;
function getImage() {
navigator.camera.getPicture(onSuccess, onFailure, {
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
});
function onSuccess(imageURI) {
imgData = encodeImageUri(imageURI);
var contentLen = imgData.length;
gapi.load('client', start);
}
function onFailure(message) {
alert("Get image failed: " + message);
}
}
function start() {
// 2. Initialize the JavaScript client library.
console.log('firing google storage api');
gapi.client.init({
'apiKey': 'XXX-XX'
}).then(function() {
// 3. Initialize and make the API request.
console.log('api initialized');
var request = …Run Code Online (Sandbox Code Playgroud) javascript client-library google-cloud-storage json-api gapi
我正在使用Google Calendar API,并试图在触发日历事件时接收推送通知https://developers.google.com/calendar/v3/push
我认为一切设置正确...
gapi.client.calendar.events.watch({
calendarId: 'primary',
resource: {
id: uuid,
type: 'web_hook',
address: window.location.href,
},
}, (err, response) => {
if (err) {
console.log('err:', err);
} else {
console.log('response:', response);
}
}).then((res) => {
console.log('res:', res);
});
Run Code Online (Sandbox Code Playgroud)
但我想不是。当我调用上面的代码时,我得到200响应
{
"kind": "api#channel",
"id": "...",
"resourceId": "...",
"resourceUri": "https://content.googleapis.com/calendar/v3/calendars/primary/events?alt=json&maxResults=250&alt=json",
"expiration": "1554203159000"
}
Run Code Online (Sandbox Code Playgroud)
我相信我也应该收到同步消息,但我没有(https://developers.google.com/calendar/v3/push#sync)
为了测试,我正在修改日历本身中的一个事件(更改标题,日期,删除等),并且我希望浏览器中会发生一些事情,但是什么也没发生。
我一般不熟悉Push通知,因此不完全确定会发生什么。
我已经通过身份验证并按照https://developers.google.com/calendar/quickstart/js显示事件
我想念什么?任何帮助都非常感谢!
提前致谢!
我有一个方法来处理来自我的谷歌JavaScript客户端(gapi)的响应:
var processResponse = function(response) {
result._state = 'loaded';
response._epoch = (new Date()).getTime();
...
Run Code Online (Sandbox Code Playgroud)
有几次我得到以下错误:
TypeError: Cannot assign to read only property '_epoch' of false
at processResponse (http://0.0.0.0:9000/scripts/services/haparaapi.js:110:31)
at wrappedCallback (http://0.0.0.0:9000/bower_components/angular-scenario/angular-scenario.js:20892:81)
at http://0.0.0.0:9000/bower_components/angular-scenario/angular-scenario.js:20978:26
at Scope.$eval (http://0.0.0.0:9000/bower_components/angular-scenario/angular-scenario.js:21967:28)
at Scope.$digest (http://0.0.0.0:9000/bower_components/angular-scenario/angular-scenario.js:21796:31)
at Scope.$apply (http://0.0.0.0:9000/bower_components/angular-scenario/angular-scenario.js:22071:24)
at http://0.0.0.0:9000/bower_components/angular-gapi/modules/gapi-client.js:121:32
at https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_GB.hE_reuZ6VdE.…/ed=1/am=AQ/rs=AGLTcCPj66Crj6soG8dKJE8lBSc_RPXXKA/cb=gapi.loaded_0:604:138
at https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_GB.hE_reuZ6VdE.…/ed=1/am=AQ/rs=AGLTcCPj66Crj6soG8dKJE8lBSc_RPXXKA/cb=gapi.loaded_0:579:311
at Object.<anonymous> (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en_GB.hE_reuZ6VdE.…1/ed=1/am=AQ/rs=AGLTcCPj66Crj6soG8dKJE8lBSc_RPXXKA/cb=gapi.loaded_0:163:76)
Run Code Online (Sandbox Code Playgroud)
这个错误通常不会发生,所以我没有设法记录响应的实际情况.
错误是什么意思?我不应该为响应分配值吗?
我有两个gmail帐户,我创建了一个包含五条消息的帖子,并在此页面上使用gmail gapi进行了检索https://developers.google.com/gmail/api/v1/reference/users/threads/get.
这就是我得到的:
正如您所看到的,ID不匹配,尽管它们识别完全相同的字母.为什么会这样,我怎样才能获得统一ID?
PS我这样做的真正原因是我需要使用gmail API发送回复消息,但要做到这一点,您需要知道您回复的消息的ID.如果我回复带有id的消息(不是接收者拥有的消息ID),它只会发送一条"新"消息.
如何使用Gmail API发送回复?
先感谢您.
我在ReactJS Webpack应用程序中使用https://www.npmjs.com/package/googleapis.它确实有一个警告,它是一个alpha版本,所以问题是可以预料的,这就是我所拥有的.
npm install googleapis --save安装googleapis好了,添加"googleapis": "^2.0.2"到我的package.json,但是当我运行时,grunt build我得到以下警告(后面跟着很多错误,我会根据请求发布,因为它是很多文本):
WARNING in ./~/googleapis/apis/index.js
Critical dependencies:
41:23-44 the request of a dependency is an expression
@ ./~/googleapis/apis/index.js 41:23-44
WARNING in ./~/googleapis/~/request/~/hawk/~/hoek/lib/index.js
Critical dependencies:
403:34-60 the request of a dependency is an expression
@ ./~/googleapis/~/request/~/hawk/~/hoek/lib/index.js 403:34-60
Run Code Online (Sandbox Code Playgroud)
违规行~/googleapis/apis/index.js是:
var Endpoint = require(endpointPath);
Run Code Online (Sandbox Code Playgroud)
我得到的错误之一:
ERROR in ./~/googleapis/~/request/~/hawk/~/hoek/lib/index.js
Module not found: Error: Cannot resolve module 'fs' in /Users/dev/wwb-web-app/node_modules/googleapis/node_modules/request/node_modules/hawk/node_modules/hoek/lib
@ ./~/googleapis/~/request/~/hawk/~/hoek/lib/index.js 3:9-22
Run Code Online (Sandbox Code Playgroud)
在我的React组件中需要googleapis的代码:
var gapi = require('googleapis'); …Run Code Online (Sandbox Code Playgroud) 我试图使用谷歌驱动器api获取文件,默认情况下该文件不可共享我想让它可共享.
这是我的代码: -
<script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
<script src="https://apis.google.com/js/client.js"></script>
// The Browser API key obtained from the Google Developers Console.
// Replace with your own Browser API key, or your own key.
var developerKey = 'XXXXXXXXXX_ff_NX66eb-XXXXXXXXXXX';
// The Client ID obtained from the Google Developers Console. Replace with your own Client ID.
var clientId = "XXXXXXXXXX-hs4ujaro5sc3d0g8qndtcq2tl279cfm1.apps.googleusercontent.com"
// Replace with your own App ID. (Its the first number in your Client ID)
var appId = "XXXXXXXXXX";
// Scope to use to access …Run Code Online (Sandbox Code Playgroud) 为了使请求Youtube Data API的youtube.channels.list与mine设定参数true,我必须做出适当的授权请求,即我需要提供绑定到该通道的令牌.
为了获得该令牌,我从这里使用Google客户端库:
<script src="//apis.google.com/js/client:platform.js"></script>
Run Code Online (Sandbox Code Playgroud)
这使我能够代表某个Google帐户发出身份验证请求.
考虑到这一点,我有这个代码:
var parameters = {
'clientid': 'CLIENT_ID',
'scope': 'https://www.googleapis.com/auth/plus.profile.emails.read https://www.googleapis.com/auth/youtube.readonly',
'cookiepolicy': 'single_host_origin',
'include_granted_scopes': true,
'callback': 'googleLogin'
};
gapi.auth.signIn(parameters);
...
window.googleLogin = (authResult) => {
if (authResult[ 'error' ] == 'immediate_failed') return;
if (authResult[ 'status' ][ 'signed_in' ]) {
// make GET request to https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true
// with Authorization header `Bearer ${gapi.auth.getToken().access_token}`
} else {
console.log("singned out");
}
};
Run Code Online (Sandbox Code Playgroud)
现在的问题是,在我选择我的Google帐户之后,让我们说Youtube帐号.2,我得到的结果好像我选择了主要的Youtube帐户.
所以这里的问题是我得到的令牌gapi.auth不以任何方式考虑我选择的Youtube帐户,它总是为主帐户生成令牌(第1号).
google-authentication google-account youtube-data-api gapi google-signin
tl / dr是否所有100个使用相同客户端ID的设备都具有100个用户,具有自己的限制或一个用户共享限制?
我有一个可读写Google表格的网页。
因为该网页需要知道某个单元是否已更改,所以它每1000毫秒轮询一次服务器:
var pollProcId = window.setInterval(pollForInput, 1000);
Run Code Online (Sandbox Code Playgroud)
一个在哪里pollForInput:
gapi.client.sheets.spreadsheets.values.get(request).then(callback);
Run Code Online (Sandbox Code Playgroud)
当我尝试将这个应用程序与100名学生一起使用时,我收到许多429错误代码(超过成功读取的错误代码),以响应google.apps.sheets.v4.SpreadsheetsService.GetValues请求:
我的许多用户都没有看到甚至第一个请求回来的消息。
AnalyticsDefaultGroupUSER-100s据错误响应页面,据我所知,这些是错误:
表示每位用户每项目配额每100秒的请求已用尽。
但是由于我的应用程序每1000毫秒仅请求一次,因此我不希望看到这么多429s,因为我每100秒(每秒1个)的请求数限制为100,因此只有其应用程序在100秒内未完成的用户才应已经收到了429。
我知道我应该实现指数退避(我保证,我会做的),但是我担心我误解了这种情况下的“用户”。
每个用户都使用他们自己的设备(因此大概具有不同的IP地址),但是他们都使用我的“客户端ID”。
这种情况是计数每秒发出一个请求的用户数量是多少,还是每秒发出一百个请求的单个用户数量?
我已经设法将Google日历嵌入到React组件中,但是问题是我可以观察到嵌入式日历没有获得最新事件,该事件已添加到通过验证的电子邮件中gapi。
日历iframe网址是这个 https://calendar.google.com/calendar/b/1/embed?src={VALID_CALENDAR_EMAIL}
calendar.util.js
const CALENDAR_EMBED_BASE_URL =
'https://calendar.google.com/calendar/embed?src=';
export const getCalendarEmbedUrl = email =>
`${CALENDAR_EMBED_BASE_URL}${email}`;
Run Code Online (Sandbox Code Playgroud)
CalendarIframe.jsx组件
import React, { PureComponent } from 'react';
import { getCalendarEmbedUrl } from 'calendar.util.js';
class CalendarIframe extends PureComponent {
render() {
const { email } = this.props;
const embedUrl = getCalendarEmbedUrl(email);
return (
<div className="calendarEmbedWrapper">
<iframe
title="Calendar"
id="calendarEmbed"
width="100%"
src={embedUrl}
/>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
如何确保嵌入式日历具有应有的动态性?
我在应用程序中使用Google的api客户端。我有一个名为的函数initialize,该函数gapi.load用于验证我的凭据并加载youtube api。
gapi.load接受一个回调函数,该函数是I authenticate和loadYoutubeApi异步进行的。我想知道,当我运行initialize函数时,这些异步函数何时完成。我有没有办法在此异步回调函数中返回一个值,以便在调用时知道initialize这些异步任务已完成?谢谢!
const apiKey = 'my-api-key';
const clientId = 'my-client-id';
const authenticate = async () => {
const { gapi } = window;
try {
await gapi.auth2.init({ clientId });
console.log('authenticated');
} catch (error) {
throw Error(`Error authenticating gapi client: ${error}`);
}
};
const loadYoutubeApi = async () => {
const { gapi } = window;
gapi.client.setApiKey(apiKey);
try {
await gapi.client.load('https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest');
console.log('youtube api loaded');
} catch (error) …Run Code Online (Sandbox Code Playgroud) gapi ×10
javascript ×7
google-api ×2
reactjs ×2
async-await ×1
drive ×1
gmail ×1
gmail-api ×1
google-oauth ×1
iframe ×1
json-api ×1
node.js ×1
webpack ×1