使用 Oauth 访问 Zend Gdata 和 Gmail 源
在 Zend Gdata 模块中,有自己的文档和日历类,但没有 Gmail 类。你知道任何可行的例子吗?
因为我自己无法使用 Gmail。我可以轻松地从 Oauth 获取令牌,并且 Zend 提供的库可以完美运行,例如 Zend_Gdata_Docs。
我只是证明我的观点:
$token = unserialize($this->user->google_token);
$httpClient = $token->getHttpClient($google_oauth_config);
$client = new Zend_Gdata_Docs($httpClient);
// Retrieve user's list of Google Docs
$feed = $client->getDocumentListFeed();
foreach( $feed->entries as $entry )
{
$docs[] = $entry;
}
我得到了我应该得到的文档。
但如何获取电子邮件呢?没有现成的客户端,所以我尝试将请求强制发送到正确的端点:
$token = unserialize($this->user->google_token);
$httpClient = $token->getHttpClient($google_oauth_config);
$httpClient->setUri("https://mail.google.com/mail/feed/atom");
$response = $httpClient->request();
但是像这样直接访问它似乎会破坏某些内容/或某些内容无法完成。 Google 告诉我 401 未经授权的访问。
为了进一步缩小问题范围,我更改了我的工作文档代码,以便手动设置 URI,然后执行相同的直接 request() (我根本不使用该 Gdata_Docs 类),并且它还会在 Google 端引发错误。所以问题似乎出在那个直接的请求上。
如果有人可以提供任何有用的意见应该做什么,我将不胜感激!或者我是否需要创建新类,扩展 Gdata 并尝试这种方式?这就是我能想到的一切。
In Zend Gdata modules there is own classes for Docs and Calendar, but not any for Gmail. Do you know any working examples?
Because I cant get gmail work myself. I get tokens from Oauth with ease and libraries that Zend does provide work flawlessy, like Zend_Gdata_Docs.
I just prove my point:
$token = unserialize($this->user->google_token);
$httpClient = $token->getHttpClient($google_oauth_config);
$client = new Zend_Gdata_Docs($httpClient);
// Retrieve user's list of Google Docs
$feed = $client->getDocumentListFeed();
foreach( $feed->entries as $entry )
{
$docs[] = $entry;
}
And I get docs like i should.
But how to get emails? There's no ready client for it, so i tried just force request to the right endpoint:
$token = unserialize($this->user->google_token);
$httpClient = $token->getHttpClient($google_oauth_config);
$httpClient->setUri("https://mail.google.com/mail/feed/atom");
$response = $httpClient->request();
But accessing it directly like that seems to broke something / or something does not get done. Google says me that 401 unauhtorized access.
To narrow the problem more, i changed my working docs code so, that i set URI manually and then do the same direct request() (i don't use that Gdata_Docs class at all) and it also fires error in Google's end. So the problem seems to be in that direct request.
If anyone could have any helpful input what should be done, i'd be more than grateful! Or do i need to create new class, extending Gdata and try it that way? It's all that i can come up with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你可以尝试一下。
may be you can try it.