使用 Oauth 访问 Zend Gdata 和 Gmail 源

发布于 2024-12-14 14:41:46 字数 1076 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南巷近海 2024-12-21 14:41:46

也许你可以尝试一下。

    $httpClient = $accessToken->getHttpClient($this->_oAuthOptions);
    ($httpClient instanceof Zend_Gdata_HttpClient);
    $httpClient->setUri("https://mail.google.com/mail/feed/atom/");
    $httpClient->setParameterGet('server', 'mail');
    $httpClient->setMethod('GET');
    $response = $httpClient->request();
    print_r($response);

may be you can try it.

    $httpClient = $accessToken->getHttpClient($this->_oAuthOptions);
    ($httpClient instanceof Zend_Gdata_HttpClient);
    $httpClient->setUri("https://mail.google.com/mail/feed/atom/");
    $httpClient->setParameterGet('server', 'mail');
    $httpClient->setMethod('GET');
    $response = $httpClient->request();
    print_r($response);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文