Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am currently developing a ubuntuone Bada app. I can get the tokens via the api, but if I try to request any other part of the api I just get an empty browser window or no event fired in the http listener of the app.

My request url looks like this:

https://one.ubuntu.com/api/file_storage/v1?oauth_consumer_key=abc&oauth_token=def&oauth_nonce=xdobeqcqyfjnzjsh&oauth_timestamp=1328656660424&oauth_signature_method=PLAINTEXT&oauth_version=1.0&oauth_signature=uvw%26xyz

I found the parameters on various sites and I am not sure if they are valid.

Thanks for your help!!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You need to use the token details you have to sign the request with the OAuth protocol.

Here's an example Python script, to be run on Ubuntu, which will sign a URL and then print out that URL; if you then request that URL, it should work.

Let me know if this is still problematic. (Note: the API returns data as content-type application/json, so this may not be loaded in a mobile browser.)

import oauth, urlparse, sys
from ubuntuone.couch.auth import *
if __name__ == "__main__":
  # If you already have token details, then use them here; you'll need
  # access_token, token_secret, consumer_key, and consumer_secret. This
  # script fetches them from a running Ubuntu instead.
  try:
      credentials = get_oauth_credentials()
  except CredentialsNotFound:
      print "COULDN'T GET CREDENTIALS"
      sys.exit()
  access_token = credentials['token']
  token_secret = credentials['token_secret']
  consumer_key = credentials['consumer_key']
  consumer_secret = credentials['consumer_secret']

  # Now we have token details; let's use them to sign a request.

  token = get_oauth_token(access_token, token_secret)
  consumer = oauth.OAuthConsumer(consumer_key, consumer_secret)

  url = "https://one.ubuntu.com/api/file_storage/v1"
  request_body = ""
  signature_method = HMAC_SHA1

  parameters = {}
  query = urlparse.urlparse(url)[4]
  for key, value in urlparse.parse_qs(query).items():
      parameters[key] = value[0]

  request_len = len(request_body) if request_body else 0
  timeout = 10 * (request_len / 1024 / 1024 + 1)  # 10 seconds per megabyte

  oauth_request = oauth.OAuthRequest.from_consumer_and_token(
      http_url=url,
      http_method="GET",
      oauth_consumer=consumer,
      token=token,
      parameters=parameters)
  oauth_request.sign_request(signature_method, consumer, token)
  print oauth_request.to_url()
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.