在 Zend GData 中获取 AuthSub 当前用户
我使用 Zend Gdata 将用户连接到共享的 Google Docs 电子表格,该电子表格充当自定义界面的后端。
我需要跟踪哪个用户最近更改了特定列中的值。我不知道如何使用 Google Spreadsheets 来做到这一点(但这对于我的问题来说是一个可以接受的答案)。
有没有办法获取当前通过 AuthSub 登录的用户的用户名/电子邮件地址,无论是使用从 Google 返回的令牌还是通过其他方法?
I'm using Zend Gdata to connect users to a shared Google Docs spreadsheet that serves as a backend to a custom interface.
I need to track which user most recently changed the value in a particular column. I'm not aware of a way to do this using Google Spreadsheets (but that would be an acceptable answer to my question).
Is there a way to get the username/email address of the user currently logged in through AuthSub, either using the token returned from Google or by another method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是这样做,所以我可以帮助你。
当然,你需要先通过 google 进行身份验证,听起来你已经做到了这一点,所以我不打算在这里概述它,因为我没有用 php 来实现这一点。但这并不重要,因为谷歌返回 xml,您只需要解析它即可获取它。
在控制器中,您可以打印 xml 以查看它是如何返回的。如果这对您来说没有意义,那么您需要知道的是,在 xml 文档中,第一个元素中有一个包含用户电子邮件的内容。而且,您可以只解析 xml,以便从电子邮件中获取用户名。
对于 ruby,我是这样做的:
xml 通过 gdata 返回,它使用 ruby gem,但它应该与 php 相同。它使用以下代码调用 google。无论如何,并不真正应该让 xml 返回给您,您只需要访问第一个元素的 id 即可。
I just did this so I can help you out.
Of course you need to get authenticated with google first and it sounds like you already got this going so I'm not going to outline it here as I didn't get this going with php. But that doesn't matter as google returns xml and you just need to parse it to get the it.
In you controller you can print the xml to see how it is getting returned. If that doesn't make sense to you, then all you need to know is that in the xml document the first element has an with the users email within it. And, you can just parse the xml so that you get the users name from the email.
With ruby I did it like this:
The xml is getting returned with gdata, which is using the ruby gem but it should be the same as php. It calls google with the following code. Doesn't really as you should be getting xml returned to you anyhow and you just need to acces that first element's id.
假设 $gspreadsheet 是一个经过身份验证的 Zend_Gdata_Spreadsheets 对象,请尝试:
$gspreadsheet->getUserProfile("default")->username->text;
Assuming that $gspreadsheet is an authenticated Zend_Gdata_Spreadsheets object, try:
$gspreadsheet->getUserProfile("default")->username->text;