首页 \ 问答 \ PHP Google API客户端不一致无法加载正确的凭据(PHP Google API Client Inconsistency not loading proper credentials)

PHP Google API客户端不一致无法加载正确的凭据(PHP Google API Client Inconsistency not loading proper credentials)

基本上,我一直在使用PHP Google API客户端库来访问多个用户的gmail收件箱(他们允许通过oAuth2工作流访问)并提取一些数据......

观察:客户端仅在10到15分钟后才能正确验证...一旦使用令牌验证用户的gmail收件箱,该用户就可以访问数据。 但是当下一个令牌用于验证另一个用户的gmail收件箱时,PHP google api客户端不会重新加载,而是使用前一个用户(我怀疑它已被缓存/存储在会话中)。

代码流程:

<?php
$tokenArray = array();
foreach($tokenArray as $token) {
 $googleclient = getGoogleClient($token);
 //$googleclient is stale even after the second iteration of the foreach loop
 $service = new Google_Service_Gmail($googleclient);
 $googleuser = "me";
 //if we change the variable $googleuser to some email address "xyz@gmail.com", we get a "Delegation denied for xyz@gmail.com"
 $userprofile = $service->users->getProfile($googleuser);
 var_dump($userprofile);//same data
}
?>

如果我们将它从循环中取出并在25-30分钟之后进行单独调用(或重新启动apache webserver),则第二个令牌将在客户端库中正确使用。

是因为Google API PHP客户端库正在缓存对象并重复使用它30分钟或者我错过了什么?

我的问题是在处理多个令牌时我应该怎么做才能重新加载客户端?

有没有正确的方法/任何其他方式来初始化客户端?

你们中的任何人都有PHP Google API客户端库的任何代码片段...我已经在官方文档中检查过但无济于事......

谢谢你的帮助


Basically, I've been using the PHP Google API Client library for accessing gmail inbox of multiple users(who've allowed access through a oAuth2 workflow) and extracting some data...

Observations: The Client gets authenticated properly only after 10 to 15 mins of time... Once a token is used to authenticate a user's gmail inbox, data is accessible for that user. but when the next token is used to authenticate another user's gmail inbox, the PHP google api client doesn't reload but uses the previous user(I suspect it's been cached / stored in session).

Code flow:

<?php
$tokenArray = array();
foreach($tokenArray as $token) {
 $googleclient = getGoogleClient($token);
 //$googleclient is stale even after the second iteration of the foreach loop
 $service = new Google_Service_Gmail($googleclient);
 $googleuser = "me";
 //if we change the variable $googleuser to some email address "xyz@gmail.com", we get a "Delegation denied for xyz@gmail.com"
 $userprofile = $service->users->getProfile($googleuser);
 var_dump($userprofile);//same data
}
?>

if we take it out of the loop and make separate calls after 25 - 30 mins(or restart the apache webserver), The second token is used in the client library properly.

Is it because the Google API PHP Client Library is caching the object and reusing it for 30 mins or am I missing something?

My question is what should I do to reload the client while handling more than one token?

Is there a proper way / any other way to initialize the client?

Do any of you have any code snippets for PHP Google API Client library... I've checked it in the official docs but to no avail...

Thanks for any help


原文:https://stackoverflow.com/questions/35655668
更新时间:2024-01-02 09:01

最满意答案

我认为是因为你试图定义一个匿名函数。 控制台没有未来的引用方式,所以它是一个毫无意义的努力,你定义一个你无法调用的函数。 如果将其定义为变量,则可以:

 var a = function () {}.bind(null); 

我也不认为它的约束力相关。 定义一个没有绑定的匿名函数,你有同样的错误

编辑

以关键字“function”开头的语句必须是有效的函数声明语句。 这需要函数的名称。

在表达式(或表达式语句)中,该规则是不同的; 不需要名称,因为该函数在该上下文中充当值。 那时不需要名字。

函数声明不能​​是匿名的,但函数表达式可以。 独立匿名函数看起来像缺少JavaScript标识符的函数声明。 但是,结合运算符,JavaScript将匿名函数视为运算符的操作数表达式。


I think its because you are trying to define an anonymous function. Console has no future way of referencing it so its a pointless endeavour, youre defining a function you have no way of calling. If you define it as a variable it works:

 var a = function () {}.bind(null); 

Also I dont think its binding related. Defining an anonymous function without binding and you have the same error

Edits

A statement that begins with the keyword "function" must be a valid function declaration statement. That requires a name for the function.

In an expression (or expression statement), that rule is different; no name is necessary because the function acts as a value in that context. No name is required then.

A function declaration cannot be anonymous, but a function expression can. A stand alone anonymous function looks like a function declaration that is missing an identifier to JavaScript. But, combined with an operator, JavaScript treats an anonymous function as the operator's operand expression.

相关问答

更多
  • 你用这个: delegate void CaptureCallback (UIImage processedImage, NSError); [BaseType (typeof (GPUImageVideoCamera))] interface GPUImageStillCamera { [Export ("capturePhotoAsJPEGProcessedUpToFilter:withCompletionHandler:")] void CapturePhot ...
  • 正如您所提到的,如果您在函数参数列表的开头使用this参数,剩余的参数将在以后绑定,则可以使用partial 。 对于你的this参数位置阻止你使用partial你可以使用匿名函数文字 ,它比函数文字更加简洁( (fn [args...] body) ): (defn abc [arg1 arg2 this] ...) (do-sth #(abc %1 %2 this)) As you mentioned you can use partial if your this parameter at the ...
  • 为什么不问问文档 : 属性的子属性可以通过类似于C#中使用的语法来指定。 例如,子句Path = ShoppingCart.Order将绑定设置为对象或属性ShoppingCart的子属性Order。 当源是集合视图时 ,可以用斜线(/)指定当前项目。 例如,子句Path = /设置绑定到视图中的当前项目。 当源是集合时,此语法指定默认集合视图的当前项目。 (为方便起见添加了Collection视图链接) 这就像它得到的一样简洁和完整。 使用. 对其中一件物品的收藏品进行记号甚至没有意义。 例如Collec ...
  • 我相信这意味着你绑定到任何绑定上下文的根。 因此,如果您在作为某种列表控件的一部分的datatemplate中使用此语法,那么您将绑定到父控件(列表控件)绑定到的任何根级别。 I believe it means you are binding to the root of whatever the binding context is. So if you use this syntax in a datatemplate that is part of some sort of list control ...
  • 协议实际上只是内嵌到您的界面中,因此您可以直接将属性内联到您的类中,或者您可以让生成器为您内联这些属性。 // Notice the lack of [BaseType] attribute on this one interface GRGrabbaPreferencesProtocol { [Export ("baseName")] string BaseName { get; } } [BaseType (typeof (NSObject))] interface GRGrabbaP ...
  • 我认为是因为你试图定义一个匿名函数。 控制台没有未来的引用方式,所以它是一个毫无意义的努力,你定义一个你无法调用的函数。 如果将其定义为变量,则可以: var a = function () {}.bind(null); 我也不认为它的约束力相关。 定义一个没有绑定的匿名函数,你有同样的错误 编辑 以关键字“function”开头的语句必须是有效的函数声明语句。 这需要函数的名称。 在表达式(或表达式语句)中,该规则是不同的; 不需要名称,因为该函数在该上下文中充当值。 那时不需要名字。 来自@Poi ...
  • Lang绑定的解析器位于https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding/Parse/Binding/Lang/MvxLanguageBindingParser.cs 它为每个Lang绑定解析4件事: 键 - 文本查找 - 用作Converter的参数 Source - 默认为“TextSource” - 实际上这用作绑定路径 转换器 - 使用的值转换器(默认为“语言”) FallbackValue ...
  • 可以是你最初设置vm.doctors = []; 和一次性绑定将此作为最终值? 这可以解释当$http.get完成时不更新值,这在变量稳定后处于完全不同的摘要周期。 然后第一次在get callback中设置此变量应该可以解决问题。 如果允许进一步更新集合(例如在滚动时加载更多项目),请不要在集合上设置一次性绑定,而只在项目上设置。 Can it be that you set initially vm.doctors = []; and one-time binding gets this as fina ...
  • 您显示的两个代码片段将Binding类实例化为MarkupExtension并允许它为CommandBehaviour的CommandParameter属性提供值。 第二种变体(你称之为“嵌套XAML”)可以被称为实例化Binding类并提供属性值的规范方式:类名是元素名,每个属性都是一个属性,它遵循所有的约定。 XML:必须引用所有属性值。 当然,如果需要使用标记扩展来设置许多属性,这种规范语法很重,因此引入了另一种简短的语法:如果需要使用标记扩展Binding设置名为CommandParameter的属 ...
  • 表达式必须以:: 开头才能被视为一次性绑定( docs )。 否则,当Angular尝试编译它时,它只会导致无效的JavaScript。 var app = angular.module('app', []); app.controller('Ctrl', function($scope, $timeout) { $scope.oneTimeBinding = 'FOO'; // change oneTimeBinding property after 2 seconds $ ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)