如何在odoo中使用oauth访问令牌访问gmail

时间:2018-06-29 06:23:55

标签: python-2.7 odoo-11

@api.multi
    def connect(self):
      user = self.env['res.users']
      aouth_id = self.env['auth.oauth.provider'].search([('enabled', '=', True)])
      user_ids = user.search([('id', '=', 800),('oauth_access_token', '!=', False)])

    for user in user_ids:
        partner_ids = self.search([('user_id', '=', user.id)])
        for partner in partner_ids:
            server = 'imap.gmail.com'
            port = IMAP4_SSL_PORT
            print port, "llllllll"
            connection = IMAP4_SSL(server)
            username = partner.user_id.login
            print partner.user_id.oauth_access_token
            print(oauth2.GeneratePermissionUrl(aouth_id.client_id))
            oauth2String = oauth2.GenerateOAuth2String(username,partner.user_id.oauth_access_token,base64_encode=False)
            print oauth2String, "---------===-----"
            connection.authenticate('XOAUTH2', lambda x: oauth2String)               
            print "-----", connection
            # connection.login(username, partner.user_id.oauth_access_token)
    return connection

0 个答案:

没有答案