def _get_user_authenticated(self): screen_obj = self.env['twitter.screen'] api = screen_obj._get_api() screen = api.VerifyCredentials().AsDict()['screen_name'] auth_user = screen_obj.search([('screen', '=', screen)]) if auth_user: return auth_user else: raise UserError('Screen associated to the API keys is not present in the records.')
def write(self, vals): TwitterConfig = super(ResConfigSettings, self).write(vals) if vals.get('twitter_consumer_key') and vals.get('twitter_consumer_secret') \ and vals.get('twitter_access_token_key') and vals.get('twitter_access_token_secret'): try: api = twitter.Api( vals.get('twitter_consumer_key'), vals.get('twitter_consumer_secret'), vals.get('twitter_access_token_key'), vals.get('twitter_access_token_secret') ) screen_obj = self.env['twitter.screen'] screen = api.VerifyCredentials().AsDict()['screen_name'] if not screen_obj.search([('screen', '=', screen)]): screen_obj.create({ 'screen': screen, 'my_screen': True }) except: raise AccessError(_('Incorrect Keys.')) return TwitterConfig
def _get_api(self, tweet_mode=None): try: params = self.env['ir.config_parameter'].sudo() twitter_consumer_key = params.get_param( 'media_connector.twitter_consumer_key') twitter_consumer_secret = params.get_param( 'media_connector.twitter_consumer_secret') twitter_access_token_key = params.get_param( 'media_connector.twitter_access_token_key') twitter_access_token_secret = params.get_param( 'media_connector.twitter_access_token_secret') api = twitter.Api(twitter_consumer_key, twitter_consumer_secret, twitter_access_token_key, twitter_access_token_secret, tweet_mode=tweet_mode) api.VerifyCredentials() return api except: raise TwitterError