GMail IMAP OAuth2 – A Walkthrough
This blog post covers from start to finish the process for getting a desktop application working with GMail using the IMAP protocol with OAuth2 authentication.
Start here: https://console.developers.google.com/apis/credentials
(1) The first step is to create credentials. Your app is a desktop application. HOWEVER, you will be creating credentials as if your app is a web app.
See this YouTube video demonstrating how to create the Client ID and Client Secret: https://youtu.be/EZK2ZGmfX2k
(2) The 2nd step is to get the initial OAuth2 token from a desktop application. See these examples:
C: Get GMail IMAP OAuth2 Access Token for Desktop App
Chilkat2-Python: Get GMail IMAP OAuth2 Access Token for Desktop App
C++: Get GMail IMAP OAuth2 Access Token for Desktop App
C#: Get GMail IMAP OAuth2 Access Token for Desktop App
DataFlex: Get GMail IMAP OAuth2 Access Token for Desktop App
Delphi ActiveX: Get GMail IMAP OAuth2 Access Token for Desktop App
Delphi DLL: Get GMail IMAP OAuth2 Access Token for Desktop App
Visual FoxPro: Get GMail IMAP OAuth2 Access Token for Desktop App
Go: Get GMail IMAP OAuth2 Access Token for Desktop App
Java: Get GMail IMAP OAuth2 Access Token for Desktop App
Node.js: Get GMail IMAP OAuth2 Access Token for Desktop App
Objective-C: Get GMail IMAP OAuth2 Access Token for Desktop App
Perl: Get GMail IMAP OAuth2 Access Token for Desktop App
PHP ActiveX: Get GMail IMAP OAuth2 Access Token for Desktop App
PHP Extension: Get GMail IMAP OAuth2 Access Token for Desktop App
PowerBuilder: Get GMail IMAP OAuth2 Access Token for Desktop App
PowerShell: Get GMail IMAP OAuth2 Access Token for Desktop App
PureBasic: Get GMail IMAP OAuth2 Access Token for Desktop App
CkPython: Get GMail IMAP OAuth2 Access Token for Desktop App
Ruby: Get GMail IMAP OAuth2 Access Token for Desktop App
Swift 2: Get GMail IMAP OAuth2 Access Token for Desktop App
Swift 3,4,5…: Get GMail IMAP OAuth2 Access Token for Desktop App
Tcl: Get GMail IMAP OAuth2 Access Token for Desktop App
Unicode C: Get GMail IMAP OAuth2 Access Token for Desktop App
Unicode C++: Get GMail IMAP OAuth2 Access Token for Desktop App
Visual Basic 6.0: Get GMail IMAP OAuth2 Access Token for Desktop App
VB.NET: Get GMail IMAP OAuth2 Access Token for Desktop App
VBScript: Get GMail IMAP OAuth2 Access Token for Desktop App
Xojo Plugin: Get GMail IMAP OAuth2 Access Token for Desktop App
The code to get the initial OAuth2 access token will popup a browser to allow the GMail account owner to authorize the access.
This YouTube video shows it: https://www.youtube.com/watch?v=MBwUOs_JqOM
(3) The last step is to use the access token in your application to authenticate with the GMail IMAP server. See these examples:
C: GMail IMAP Authentication using OAuth2 Access Token
Chilkat2-Python: GMail IMAP Authentication using OAuth2 Access Token
C++: GMail IMAP Authentication using OAuth2 Access Token
C#: GMail IMAP Authentication using OAuth2 Access Token
DataFlex: GMail IMAP Authentication using OAuth2 Access Token
Delphi ActiveX: GMail IMAP Authentication using OAuth2 Access Token
Delphi DLL: GMail IMAP Authentication using OAuth2 Access Token
Visual FoxPro: GMail IMAP Authentication using OAuth2 Access Token
Go: GMail IMAP Authentication using OAuth2 Access Token
Java: GMail IMAP Authentication using OAuth2 Access Token
Node.js: GMail IMAP Authentication using OAuth2 Access Token
Objective-C: GMail IMAP Authentication using OAuth2 Access Token
Perl: GMail IMAP Authentication using OAuth2 Access Token
PHP ActiveX: GMail IMAP Authentication using OAuth2 Access Token
PHP Extension: GMail IMAP Authentication using OAuth2 Access Token
PowerBuilder: GMail IMAP Authentication using OAuth2 Access Token
PowerShell: GMail IMAP Authentication using OAuth2 Access Token
PureBasic: GMail IMAP Authentication using OAuth2 Access Token
CkPython: GMail IMAP Authentication using OAuth2 Access Token
Ruby: GMail IMAP Authentication using OAuth2 Access Token
SQL Server: GMail IMAP Authentication using OAuth2 Access Token
Swift 2: GMail IMAP Authentication using OAuth2 Access Token
Swift 3,4,5…: GMail IMAP Authentication using OAuth2 Access Token
Tcl: GMail IMAP Authentication using OAuth2 Access Token
Unicode C: GMail IMAP Authentication using OAuth2 Access Token
Unicode C++: GMail IMAP Authentication using OAuth2 Access Token
Visual Basic 6.0: GMail IMAP Authentication using OAuth2 Access Token
VB.NET: GMail IMAP Authentication using OAuth2 Access Token
VBScript: GMail IMAP Authentication using OAuth2 Access Token
Xojo Plugin: GMail IMAP Authentication using OAuth2 Access Token
(4) After an hour, your access token will expire and will need to be refreshed. This example showsn how to refresh the access token:
C: Refresh GMail IMAP OAuth2 Access Token
Chilkat2-Python: Refresh GMail IMAP OAuth2 Access Token
C++: Refresh GMail IMAP OAuth2 Access Token
C#: Refresh GMail IMAP OAuth2 Access Token
DataFlex: Refresh GMail IMAP OAuth2 Access Token
Delphi ActiveX: Refresh GMail IMAP OAuth2 Access Token
Delphi DLL: Refresh GMail IMAP OAuth2 Access Token
Visual FoxPro: Refresh GMail IMAP OAuth2 Access Token
Go: Refresh GMail IMAP OAuth2 Access Token
Java: Refresh GMail IMAP OAuth2 Access Token
Node.js: Refresh GMail IMAP OAuth2 Access Token
Objective-C: Refresh GMail IMAP OAuth2 Access Token
Perl: Refresh GMail IMAP OAuth2 Access Token
PHP ActiveX: Refresh GMail IMAP OAuth2 Access Token
PHP Extension: Refresh GMail IMAP OAuth2 Access Token
PowerBuilder: Refresh GMail IMAP OAuth2 Access Token
PowerShell: Refresh GMail IMAP OAuth2 Access Token
PureBasic: Refresh GMail IMAP OAuth2 Access Token
CkPython: Refresh GMail IMAP OAuth2 Access Token
Ruby: Refresh GMail IMAP OAuth2 Access Token
Swift 2: Refresh GMail IMAP OAuth2 Access Token
Swift 3,4,5…: Refresh GMail IMAP OAuth2 Access Token
Tcl: Refresh GMail IMAP OAuth2 Access Token
Unicode C: Refresh GMail IMAP OAuth2 Access Token
Unicode C++: Refresh GMail IMAP OAuth2 Access Token
Visual Basic 6.0: Refresh GMail IMAP OAuth2 Access Token
VB.NET: Refresh GMail IMAP OAuth2 Access Token
VBScript: Refresh GMail IMAP OAuth2 Access Token
Xojo Plugin: Refresh GMail IMAP OAuth2 Access Token