我正在尝试使用 OfflineImap v7.2.1 将我的邮件从 gmail 同步到我的本地服务器。我遵循了本教程:Using Offlineimap with the Gmail IMAP API并让它工作!
这是我的.offlineimaprc
文件:
[general]
accounts = ExampleCompany
[Account ExampleCompany]
localrepository = ExampleCompanyLocal
remoterepository = ExampleCompanyRemote
postsynchook = notmuch new
#newer versions don't need this
#status_backend = sqlite
[Repository ExampleCompanyRemote]
type = IMAP
remotehost = imap.gmail.com
remoteuser = my-username@gmail.com
ssl = yes
starttls = no
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
### You'll need to configure the gmail API stuff here:
auth_mechanisms = XOAUTH2
oauth2_client_id = XXXX7-eXXXX.apps.googleusercontent.com
oauth2_client_secret = 9XXXXXP
oauth2_request_url = https://accounts.google.com/o/oauth2/token
#oauth2_refresh_token = 1/ZXXXXXw
oauth2_access_token = ya29.XXXXXIHbcS
## remove Gmail prefix on IMAP folders
nametrans = lambda f: f.replace('[Gmail]/', '') if
f.startswith('[Gmail]/') else f
[Repository ExampleCompanyLocal]
type = Maildir
localfolders = ~/mail
restoreatime = no
# Do not sync this folder
folderfilter = lambda folder: folder not in ['2007-2011-inbox']
## Remove GMAIL prefix on Google-specific IMAP folders that are pulled down.
nametrans = lambda f: '[Gmail]/' + f if f in ['Drafts', 'Starred', 'Important', 'Spam', 'Trash', 'All Mail', 'Sent Mail'] else f
我目前从谷歌生成我的Access Token
并Refresh Token
使用这个python 脚本。但是,我希望从 ios 应用程序生成此令牌,然后将其发送到后端以开始同步。我正在使用AppAuth来执行此操作,但在使用从 IOS 应用程序获取的这些凭据时,OfflineImap 总是出错。错误
ERROR: All authentication types failed:
XOAUTH2: [AUTHENTICATIONFAILED] Invalid credentials (Failure)
知道为什么这些凭据无效吗?我在运行脚本和应用程序时使用相同的client_id
。client_secret
我想我错过了一些明显的东西。
这是 swift 对应用程序的授权请求:
// builds authentication request
let request = OIDAuthorizationRequest(configuration: configuration,
clientId: "XXXX7-eXXXX.apps.googleusercontent.com",
clientSecret: "9XXXXXP",
scopes: [OIDScopeEmail],
redirectURL: redirectURI,
responseType: OIDResponseTypeCode,
additionalParameters: nil)
谢谢