使用 PubSub 获取 Gmail 未读邮件计数
我正在尝试使用 Cocoa (Mac) 和 PubSub 框架获取 Gmail 未读电子邮件计数。我已经看到一两个链接显示使用 PubSub 和 Gmail,这是到目前为止我的代码。
PSClient *client = [PSClient applicationClient];
NSURL *url = [NSURL URLWithString:@"https://mail.google.com/mail/feed/atom/inbox"];
PSFeed *feed = [client addFeedWithURL:url];
[feed setLogin: @"myemailhere"];
[feed setPassword: @"mypasswordhere"];
NSLog(@"Error: %@", feed.lastError);
有人知道如何获取未读数吗?
谢谢 :)
I'm trying to get my Gmail unread email count using Cocoa (Mac) and the PubSub framework. I've seen one or two links showing using PubSub and Gmail, here's my code so far.
PSClient *client = [PSClient applicationClient];
NSURL *url = [NSURL URLWithString:@"https://mail.google.com/mail/feed/atom/inbox"];
PSFeed *feed = [client addFeedWithURL:url];
[feed setLogin: @"myemailhere"];
[feed setPassword: @"mypasswordhere"];
NSLog(@"Error: %@", feed.lastError);
Anyone know how I can get the unread count?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有两个问题:一个有解决方案,另一个似乎是一个永恒的问题。
第一个:提要刷新是异步发生的。因此,您需要侦听 PSFeedRefreshingNotification 和 PSFeedEntriesChangedNotification 通知,以查看 feed 何时刷新和更新。通知的对象将是相关的 PSFeed。
举个例子:
第二个(也是更糟糕的)问题是 PubSub 无法正确处理经过身份验证的提要。我在 http://www.dizzey.com/ 看到了这个development/fetching-emails-from-gmail-using-cocoa/ 并且我在自己的系统上重现了相同的行为。我不知道这个 bug 是否是 10.7 特有的,或者它是否影响以前版本的 OS X。
“解决方法”是使用 NSURLConnection 对原始提要 XML 执行经过身份验证的检索。然后,您可以使用其 initWithData:URL: 方法将其推入 PSFeed 中。这样做的一个非常严重的缺点是你实际上不再是 PubSubing 了。您必须运行计时器并在适当的时候手动刷新提要。
我能做的最好的事情就是提交一个错误:rdar://problem/10475065(OpenRadar:1430409)。
您可能应该提交重复的错误,以尝试增加 Apple 修复它的机会。
祝你好运。
You have two problems: one which there's a solution for and one which seems to be a perpetual problem.
The first: Feed refreshes happen asynchronously. So you need to listen to the PSFeedRefreshingNotification and PSFeedEntriesChangedNotification notifications to see when the feed gets refreshed and updated. The notification's object will be the PSFeed in question.
As an example:
The second (and far worse) issue is that PubSub doesn't handle authenticated feeds correctly. I saw this at http://www.dizzey.com/development/fetching-emails-from-gmail-using-cocoa/ and I've reproduced the same behavior on my own system. I don't know if this bug is 10.7 specific or if it affects previous versions of OS X.
The "workaround" is to use NSURLConnection to perform an authenticated retrieval of the raw feed XML. You can then shove that into a PSFeed using its initWithData:URL: method. The very serious drawbacks with this is that you aren't actually PubSubing anymore. You'll have to run a timer and manually refresh the feed whenever appropriate.
The best I was able to do to help you out was to file a bug: rdar://problem/10475065 (OpenRadar: 1430409 ).
You should probably file a duplicate bug to try to increase the chances that Apple will fix it.
Good luck.