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

  • Home
  • SEARCH
  • 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 8674065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:36:49+00:00 2026-06-12T19:36:49+00:00

I’m trying to get into the IMAP server with OAuth, using the PHP Sample

  • 0

I’m trying to get into the IMAP server with OAuth, using the PHP Sample Code provided by Google which uses the Zend Imap class but I am failing to authenticate. Zend is giving me the error:

Zend_Mail_Storage_Exception [ Error ]: cannot select INBOX, is this a valid transport?

Annoyingly this is a rather confusing error message, for what is essentially “Invalid Credentials”. How did I know that? By debugging the actual commands being send to the IMAP socket I see this:

string(44) "NO Invalid credentials ey9if1544983wid.142
"

I have tried with telnet and a Ruby gmail_xoauth gem which suggests it is not a code issue, but something else.

Looking at the most basic level of all this, I am getting commands like this:

TAG1 AUTHENTICATE XOAUTH R0VUIGh0dHBzOi8vbWFpbC5nb29nbGUuY29tL21h......etc

This is where I get NO Invalid credentials then:

TAG2 SELECT "INBOX"

This returns BAD Unknown command and kicks me out.

I have tried searching around for people having the same problem but I find only questions and no answers. There are a few similar StackOverflow questions:

One post shows somebody having the exact same problem in Python.

This post shows somebody trying to be awkward and do it with OAuth 2, with no report of success.

There is a thread on the GMail Google Group that suggests an “Invalid Credentials” error can be resolved by going to https://accounts.google.com/DisplayUnlockCaptcha for GMail accounts and https://www.google.com/a/%5BYOURDOMAIN.COM%5D/UnlockCaptcha if you are using Google Apps, but the latter just said that my username and password were wrong when they clearly were not. Using this https://accounts.google.com/DisplayUnlockCaptcha worked fine – even though my account is a hosted App, not plain old GMail – however I still get the same errors when trying to log back in with the PHP sample code provided by Google.

I’ve tried with various hosted Google App accounts and a plain GMail account. I’ve tried switching the IMAP server from imap.gmail.com to imap.googlemail.com, nothing makes any difference.

      /**
       * Make the IMAP connection and send the auth request
       */
      $imap = new Zend_Mail_Protocol_Imap('imap.googlemail.com', '993', true);
      $authenticateParams = array('XOAUTH', $initClientRequestEncoded);
      $imap->requestAndResponse('AUTHENTICATE', $authenticateParams);

      /**
       * Print the INBOX message count and the subject of all messages
       * in the INBOX
       */
      $storage = new Zend_Mail_Storage_Imap($imap);

      echo '<h1>Total messages: ' . $storage->countMessages() . "</h1>\n";

For those with an interest, this is the specific PHP code that sets up the connection, all XOauth is handled by Google’s PHP in the same file but I skipped it.

  • 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-06-12T19:36:50+00:00Added an answer on June 12, 2026 at 7:36 pm

    I had this exact same error, and eventually realised I was using the wrong scope when requesting the OAuth permissions.

    You need to have…

    • scope=https://mail.google.com/
    • access_type=offline

    And also IMAP enabled in your Gmail account obviously. All seems good now.

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

Sidebar

Related Questions

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
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to select an H1 element which is the second-child in its group
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
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

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.