Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6833659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:00:22+00:00 2026-05-26T23:00:22+00:00

I’m trying to get my Gmail unread email count using Cocoa (Mac) and the

  • 0

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:00:22+00:00Added an answer on May 26, 2026 at 11:00 pm

    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:

    -(void)feedRefreshing:(NSNotification*)n
    {
        PSFeed *f = [n object];
        NSLog(@"Is Refreshing: %@", [f isRefreshing] ? @"Yes" : @"No");
        NSLog(@"Feed: %@", f);
        NSLog(@"XML: %@", [f XMLRepresentation]);
        NSLog(@"Last Error: %@", [f lastError]);
    
    
        if(![f isRefreshing])
        {
            NSInteger emailCount = 0;
            NSEnumerator *e = [f entryEnumeratorSortedBy:nil];
            id entry = nil;
    
            while(entry = [e nextObject])
            {
                emailCount++;
                NSLog(@"Entry: %@", entry);
            }
            NSLog(@"Email Count: %ld", emailCount);
        }
    }
    
    -(void)feedUpdated:(NSNotification*)n
    {
        NSLog(@"Updated");
    }
    
    -(void)pubSubTest
    {
        PSClient *client = [PSClient applicationClient];
        NSURL    *url    = [NSURL URLWithString:@"https://mail.google.com/mail/feed/atom/inbox"];
        PSFeed   *feed   = [client addFeedWithURL:url];
    
        [feed setLogin: @"correctUserName@gmail.com"];
        [feed setPassword: @"correctPassword"];
        NSError *error = nil;
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(feedUpdated:) name:PSFeedEntriesChangedNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(feedRefreshing:) name:PSFeedRefreshingNotification object:nil];
    
        [feed refresh:&error];
        if(error)
            NSLog(@"Error: %@", error);
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.