开发者

Get AuthSub current user in Zend GData

开发者 https://www.devze.com 2023-01-16 23:41 出处:网络
I\'m using Zend Gdata to connect users to a shared Google Docs spreadsheet that serves as a backend to a custom interface.

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?


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:

xml.elements.first.text 

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.

xml = client.get('https://www.google.com/m8/feeds/contacts/default/base?max-results=10000').to_xml


Assuming that $gspreadsheet is an authenticated Zend_Gdata_Spreadsheets object, try:

$gspreadsheet->getUserProfile("default")->username->text;

0

精彩评论

暂无评论...
验证码 换一张
取 消