我按照以下说明操作:
https://developers.google.com/identity/sign-in/web/sign-in
一切正常(登录用户),但我无法签署用户.我收到以下错误:
未捕获的gapi.auth2.ExternallyVisibleError:gapi.auth2已使用不同的选项进行初始化
执行时失败:
auth2 = gapi.auth2.init();
Run Code Online (Sandbox Code Playgroud)
(https://developers.google.com/identity/sign-in/web/sign-in#sign_out_a_user)
我需要代码示例来从我的网络应用程序中退出用户,并且还要从Google帐户中完全签署用户.
我使用以下脚本来集成谷歌身份验证
//google auth code
gapi.load('auth2', function() {//load in the auth2 api's, without it gapi.auth2 will be undefined
gapi.auth2.init(
{
client_id: '1063305095705-k68gpfhi46tbu6kv8e8tidc751hte5pb.apps.googleusercontent.com'
}
);
var GoogleAuth = gapi.auth2.getAuthInstance();//get's a GoogleAuth instance with your client-id, needs to be called after gapi.auth2.init
$scope.onLogInButtonClick=function(){//add a function to the controller so ng-click can bind to it
GoogleAuth.signIn().then(function(response){//request to sign in
console.log(response);
console.log(response.wc.wc);
console.log(response.wc.hg);
console.log(response.wc.Ph);
});
};
});
Run Code Online (Sandbox Code Playgroud)
我试图在其他一些应用程序中使用它并收到以下错误: -
gapi.auth2.ExternallyVisibleError: gapi.auth2 has been initialized with
different options. Consider calling gapi.auth2.getAuthInstance()
instead of gapi.auth2.init().
Run Code Online (Sandbox Code Playgroud)
我也包括在内
<script …Run Code Online (Sandbox Code Playgroud) 我正在使用javascript gmail api来使用threadId获取电子邮件线程.我使用以下代码:
var request = gapi.client.gmail.users.threads.get({
'userId': 'me',
'id': '123abc'
});
request.execute(function(response) {
var messages = response.messages;
});
Run Code Online (Sandbox Code Playgroud)
这是第一次特定的threadId,它工作正常.并且对于进一步的请求,即使线程有更多的电子邮件,它也会返回相同数量的消息.但是,如果我从Chrome开发者工具 - 网络选项中清除gapi网址的浏览器缓存,则响应会提供正确数量的电子邮件.
例:
- >使用threadId'123abc'执行请求,目前线程中有3封电子邮件.请求的响应是正确的,长度为3 response.messages.
- >然后我再发一封电子邮件作为回复此帖子,然后再次执行相同的请求.但是响应仍然是长度为3的旧响应response.messages.
- >尝试多次运行相同的请求但得到相同的响应.
- >然后清除此网址的浏览器缓存并再次请求,现在响应正确,长度为4 response.messages.
尝试在html页面中添加以下元标记,但不起作用:
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
Run Code Online (Sandbox Code Playgroud)
尝试添加随机数与页面网址和请求,但没有工作.
尝试使用gapi脚本链接添加随机数,但没有奏效 <script src="https://apis.google.com/js/client.js?onload=AuthIt&cacheBurster=123123123123"></script>
是否有任何代码可以禁用gapi请求缓存或任何其他方法来解决此问题?
为Gmail构建Chrome扩展程序,尝试仅检索发送给我的电子邮件.我使用本页底部的gapi线程API资源管理器进行测试.它会按预期返回仅限收件箱的项目,如下图所示.我将
https://www.googleapis.com/gmail/v1/users/me/threads?=to%3Adan%40pledgmail.com+in%3Ainbox&access_token= + thisToken
上面的API Explorer中的请求URL复制并粘贴到我下面的background.js代码中,但除了我收到的那些之外,我还收到了我发送的电子邮件.
注意:我确实将请求URL中的"密钥"从API资源管理器更改为"access_token",否则我无法生成任何请求.
(如果我的代码没有放弃,我是新手.真诚地感谢任何帮助,我很感激你的时间.)
Google API Explorer结果(预期)

我的代码来自background.js,带有复制的请求URL
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete') {
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
thisToken = token
chrome.runtime.onMessage.addListener(
function(request,sender,sendResponse){
var gapiRequestAllThreadsToSelf = "https://www.googleapis.com/gmail/v1/users/me/threads?=to%3Adan%40pledgmail.com+in%3Ainbox&access_token=" + thisToken
var getAllThreadsToSelf = function (gapiRequestURL)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", gapiRequestURL, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
var threadsToSelf = getAllThreadsToSelf(gapiRequestAllThreadsToSelf)
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {data: threadsToSelf}, function(response) { …Run Code Online (Sandbox Code Playgroud) 试图只检索发送给我的邮件(而不是我的外发邮件),在这种情况下,我发送了一封电子邮件,并且已经回复了.当我使用以下请求时,我得到的线程只包含所需的传入消息:
"https://www.googleapis.com/gmail/v1/users/me/threads?q=-from%3Ame+in%3Ainbox&access_token=" + thisToken
Run Code Online (Sandbox Code Playgroud)
但是,当我从返回中获取消息ID并将其插入单个消息请求时:
"https://www.googleapis.com/gmail/v1/users/me/messages/" + messageId + "?access_token=" + thisToken
Run Code Online (Sandbox Code Playgroud)
返回的消息是线程中的第一条消息,在这种情况下是我的外发消息.我已经在API Explorer中演示了这一点.是否可以获取仅传入消息的消息ID?Thread API Explorer能够对其进行排序这一事实让我相信它有可能......
(我是新手.真心感谢任何帮助,我很感激你的时间.)


我使用Meteor作为应用程序框架,并使用该accounts-google软件包对用户进行身份验证。使用帐户包非常好,因为它可以处理获取访问令牌,在到期时刷新令牌等所有繁琐的工作。但是,我希望获得有关用户的更多配置文件信息,而不是Meteor.user()对象中填充的信息。
借助Facebook,我能够轻松地使用Meteor.user().services.facebook.accessToken和遵循API上的文档来加载其客户端JS库并发出图api请求:
https://developers.facebook.com/docs/javascript/reference/FB.api
在引用Google的JavaScript API时,文档指出,在进行API调用时,该请求会自动包括访问令牌,但仅在使用gapi处理授权请求时才包含。
https://developers.google.com/api-client-library/javascript/features/authentication#MakingtheAPI请求
当依赖第三方授权包时(或当您的应用程序从客户端处理Google的身份验证时),这没有帮助。
是否可以使用gapi.client库方法在请求中使用现有访问令牌?
我正在使用Google One-Tap登录来对用户进行身份验证,并且在对用户进行身份验证后,我会获得访问令牌。我知道我可以使用此访问令牌来与JavaScript的Google API客户端(“ GAPI”)一起使用。但是我找不到使用此访问令牌的GAPI使用任何方法。
假设我已经有一个登录用户,是否可以使用GAPI?
我想要做的是简单地通过一次点击身份验证进行身份验证并对用户日历进行一次同意之后,访问用户日历。
google-api google-api-js-client gapi google-identity google-api-javascript-client
gapi ×7
gmail-api ×3
gmail ×2
javascript ×2
access-token ×1
api ×1
google-api ×1
google-api-javascript-client ×1
login ×1
logout ×1
meteor ×1