Beispiel #1
0
 def twitter_wall_authenticate(self, wall):
     """ Authenticate twitter account """
     auth = Oauth(wall.stream_id.twitter_api_key, wall.stream_id.twitter_api_secret)
     callback_url = '%s/%s/%s' % (request.env['ir.config_parameter'].get_param('web.base.url'), 'twitter_wall/callback', wall.id)
     HEADER = auth._generate_header(auth.REQUEST_URL, 'HMAC-SHA1', '1.0', callback_url=callback_url)
     HTTP_REQUEST = Request(auth.REQUEST_URL)
     HTTP_REQUEST.add_header('Authorization', HEADER)
     request_response = urlopen(HTTP_REQUEST, '').read()
     request_response = auth._string_to_dict(request_response)
     if request_response['oauth_token'] and request_response['oauth_callback_confirmed']:
         url = auth.AUTHORIZE_URL + '?oauth_token=' + request_response['oauth_token']
     return request.redirect(url)
Beispiel #2
0
 def twitter_wall_callback(self, wall, **kwargs):
     """ Return to this method if authorize app is success or cancel(denied kwargs) """
     if not kwargs.get('denied'):
         auth = Oauth(wall.stream_id.twitter_api_key, wall.stream_id.twitter_api_secret)
         access_token_response = Oauth._access_token(auth, kwargs.get('oauth_token'), kwargs.get('oauth_verifier'))
         wall.write({
             'twitter_access_token': access_token_response['oauth_token'],
             'twitter_access_token_secret': access_token_response['oauth_token_secret'],
             'auth_user': access_token_response['user_id']
         })
         wall.stream_id.restart()
         return http.local_redirect('/twitter_wall/view/%s' % (wall.id))
     return http.local_redirect('/twitter_walls')