Question

I'm trying to make authenticated calls to the Bitbucket REST API, with Oauth authentication. I've successfully retrieved an oauth_token and an oauth_token_secret (although they are the same as the request_token and request_token_secret, which seems strange but not outside of the spec). When I make an API call to another endpoint, I get a 401 (not authenticated). I've tried using header authentication and/or passing the oauth_token and oauth_token_secret as HTTP params with the sane result.

Here's the code:

account_name_url = 'https://api.bitbucket.org/1.0/user'

feedback_oauth_hook = OAuthHook(
    access_token='REDACTED',
    access_token_secret='ALSO_REDACTED',
    consumer_key=CLIENT_ID,
    consumer_secret=CLIENT_SECRET,
    header_auth=True
    )

params = {
    'access_token': auth_tokens['access_token'],
    'access_token_secret': auth_tokens['access_secret']
    }

response = requests.get(account_name_url, data=params, hooks={'pre_request': feedback_oauth_hook})

No correct solution

OTHER TIPS

import oauth2  #pip install oauth2
accessToken = oauth2.Token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
consumer_key = YOUR_COMSUMER_KEY
consumer_secret = YOUR_CONSUMER_SECRET
consumer = oauth2.Consumer(consumer_key, consumer_secret)
client = oauth2.Client(consumer, accessToken)
api_url = "https://api.bitbucket.org/1.0/user"
resp, content = client.request(api_url, "GET")
print resp, content

The above python code works for me.

I print the request info, notice that it contains oauth_version=1.0 which is required. I tried removing it, then 401 was returned. I think BitBucket should document this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top