本文整理匯總了Python中oauth.OAuthRequest.to_url方法的典型用法代碼示例。如果您正苦於以下問題:Python OAuthRequest.to_url方法的具體用法?Python OAuthRequest.to_url怎麽用?Python OAuthRequest.to_url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類oauth.OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest.to_url方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: netflix_movie_from_title
# 需要導入模塊: from oauth import OAuthRequest [as 別名]
# 或者: from oauth.OAuthRequest import to_url [as 別名]
def netflix_movie_from_title(cur_movie, only_id=False):
movie = Movies()
if cur_movie and cur_movie.Title and cur_movie.Year:
try:
# Query netflix search API with OAuth
consumer = {
"oauth_token": settings.API_KEYS["NETFLIX"],
"oauth_token_secret": settings.API_KEYS["NETFLIX_SECRET"],
}
params = {"term": cur_movie.Title, "start_index": 0, "max_results": 5}
request = OAuthRequest("http://api-public.netflix.com/catalog/titles", "GET", params)
request.sign_request(OAuthSignatureMethod_HMAC_SHA1, consumer)
url = request.to_url(include_oauth=True)
req = urllib2.Request(url)
res = urllib2.urlopen(req)
if res.getcode() == 200:
# Parse xml response
dom = parseString(res.read())
for node in dom.getElementsByTagName("catalog_title"):
# If year is the same
if (
node.getElementsByTagName("release_year")
and node.getElementsByTagName("release_year")[0]
and abs(cur_movie.Year - int(node.getElementsByTagName("release_year")[0].childNodes[0].data))
< 1
):
if node.getElementsByTagName("id") and node.getElementsByTagName("id")[0]:
if only_id:
return {
"id": netflix_id_from_input(
str(node.getElementsByTagName("id")[0].childNodes[0].data)
)
}
else:
return movie_from_netflix_input(node.getElementsByTagName("id")[0].childNodes[0].data)
return {"error_msg": "Invalid"}
else:
return {"error_msg": "Invalid"}
except Exception:
return {"error_msg": "Netflix API failed, please try again"}
else:
return {"error_msg": "No title to search from."}
示例2: get_netflix_dom
# 需要導入模塊: from oauth import OAuthRequest [as 別名]
# 或者: from oauth.OAuthRequest import to_url [as 別名]
def get_netflix_dom(netflix_id, href=None):
try:
# Query netflix API using OAuth
consumer = {
"oauth_token": settings.API_KEYS["NETFLIX"],
"oauth_token_secret": settings.API_KEYS["NETFLIX_SECRET"],
}
request = None
if href:
request = OAuthRequest(href)
else:
request = OAuthRequest("http://api-public.netflix.com/catalog/titles/movies/" + netflix_id)
request.sign_request(OAuthSignatureMethod_HMAC_SHA1, consumer)
url = request.to_url(include_oauth=True)
req = urllib2.Request(url)
res = urllib2.urlopen(req)
if res.getcode() == 200:
# Parse xml response
return parseString(res.read())
else:
return {"Response": False}
except Exception:
return {"Response": False}