
저는 현재 ubuntuone Bada 앱을 개발 중입니다. API를 통해 토큰을 얻을 수 있지만 API의 다른 부분을 요청하려고 하면 빈 브라우저 창이 나타나거나 앱의 http 리스너에서 이벤트가 실행되지 않습니다.
내 요청 URL은 다음과 같습니다.
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
다양한 사이트에서 매개변수를 찾았는데 그것이 유효한지 확실하지 않습니다.
당신의 도움을 주셔서 감사합니다!!
답변1
필요한 토큰 세부 정보를 사용해야 합니다.요청에 서명하세요OAuth 프로토콜을 사용합니다.
다음은 Ubuntu에서 실행되는 Python 스크립트의 예입니다. 이 스크립트는 URL에 서명한 다음 해당 URL을 인쇄합니다. 그런 다음 해당 URL을 요청하면 작동합니다.
여전히 문제가 있으면 알려주세요. (참고: API는 데이터를 content-type 으로 반환하므로 application/json
모바일 브라우저에서는 로드되지 않을 수 있습니다.)
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()