Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:44:38+00:00 2026-06-09T20:44:38+00:00

I am trying to create generic class in python which will do all the

  • 0

I am trying to create generic class in python which will do all the oAuth process and then will allow to retrieve data from any oAuth supporting service (for example Twitter,LinkedIn).

Edited:
I have customer key and secret and access token key and secret,when I try to request any resource request I get the following error:
{"error":"Could not authenticate with OAuth.","request":"\/1\/statuses\/retweeted_by_me.json}’

any idea why?

My Code is:

import httplib
import time
import oauth as oauth

# settings for the local test consumer
SERVER = 'api.twitter.com'

RESOURCE_URL = 'https://api.twitter.com/1/statuses/retweeted_by_me.json'

CONSUMER_KEY = 'MY_CUSTOMER_KEY'
CONSUMER_SECRET = 'MY_CUSTOMER_SECRET'
ACCESS_TOKEN_KEY = 'MY_ACCESS_TOKEN_KEY'
ACCESS_TOKEN_SECRET = 'MY_ACCESS_TOKEN_SECRET'

# example client using httplib with headers
class SimpleOAuthClient(oauth.OAuthClient):

    def __init__(self, server):
        self.server = server
        self.connection = httplib.HTTPSConnection(self.server)

    def access_resource(self, oauth_request):
        # via post body
        # -> some protected resources
        self.connection.request(oauth_request.http_method, RESOURCE_URL)
        response = self.connection.getresponse()
        return response.read()

def run_example2():
  print '** OAuth Python Library Example **'
  client = SimpleOAuthClient(SERVER, )
  consumer = oauth.OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET)
  signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
  pause()

  # access some protected resources
  print '* Access protected resources ...'
  pause()
  token = oauth.OAuthToken('ACCESS_TOKEN_KEY', 'ACCESS_TOKEN_SECRET')
  oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, token=token, http_method='GET', http_url=RESOURCE_URL)
  oauth_request.sign_request(signature_method_hmac_sha1, consumer, token)
  print 'REQUEST (via post body)'
  print 'parameters: %s' % str(oauth_request.parameters)
  pause()
  params = client.access_resource(oauth_request)
  print 'GOT'
  print 'non-oauth parameters: %s' % params
  pause()


def pause():
    print ''
    time.sleep(1)

if __name__ == '__main__':
    run_example2()
    print 'Done.'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:44:40+00:00Added an answer on June 9, 2026 at 8:44 pm

    I managed to fix it by changing self.connection.request(oauth_request.http_method, RESOURCE_URL)
    to self.connection.request(oauth_request.http_method, oauth_request.to_url())

    Notice that will will work only if oauth_request.http_method is GET

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a generic class which will have some static functions based
I'm trying to create a generic class in PHP that will provide a way
I am trying to create a generic class which new's up an instance of
I am trying to create a generic class to write and read Objects to/from
Using C++, I'm trying to create a generic container class to handle multiple data
I am trying to create a generic Identifier class which I would be able
I'm trying to create a UserControl that inherits from a generic class. It does
I'm trying to create a generic function in grails that will allow me to
I'm trying to have a generic 'List' class, which will have: Property: Items -
I'm trying to create an instance of a generic class using a Type object.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.