Assuming that you're asking about an OAuth library to access YQL? yes we do intend to provide a Java library for accessing yahoo oauth web services that include YQL among others.
For Python, I was able to successfully use the python client library available at http://oauth.googlecode.com/svn/code/python/oauth/ to perform both 2 legged as well as 3 legged calls.
-- Nagesh
Hi,
I have been trying to get python to make authenticated oauth requests to YQL using the code pointed to by Nagesh above but so far have had no success.
I don't have any trouble getting similar code to work from PHP and so I know that the consumer key and secret are valid and that the basic process works.
I have tried authenticating via headers, using post data and directly in the URL but always get an authorization error.
I would be very grateful if someone could help in getting this working.
Many thanks in advance,
Assif
Here is my test code:
CODE
import httplib
import oauth as oauth
import urllib
CONSUMER_KEY = '[hidden]'
CONSUMER_SECRET = '[hidden]'
def YQLget2legged (baseurl, query):
parameters = {'q':query, 'format':'xml'}
print "parameters: ",parameters
print "Create Consumer"
consumer = oauth.OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET)
print "Create Request"
oauth_request = oauth.OAuthRequest.from_consumer_and_token(oauth_consumer=consumer, http_method='GET', http_url=baseurl, parameters=parameters)
print "Sign Request"
oauth_request.sign_request(oauth.OAuthSignatureMethod_PLAINTEXT(), consumer, None)
print "Execute Request"
headers = oauth_request.to_header()
moreheaders = {'Content-Type' :'application/x-www-form-urlencoded', 'Accept':'*'}
headers.update(moreheaders)
print "Headers: ",headers
connection = httplib.HTTPConnection('query.yahooapis.com')
# Try authenticating using full URL
url=oauth_request.to_url()
print "URL: ",url
connection.request('GET', url, headers=headers)
# or using POST
#body=oauth_request.to_postdata()
#print "Body: ",body
#connection.request('POST', '/v1/yql', body=body, headers=headers)
print "Read Response"
response = connection.getresponse()
params = response.read()
print "Params returned:", params
if __name__ == '__main__':
#yql='select date, url, title, abstract from search.web(100) where query in ("foo")'
yql='show tables'
query = urllib.quote(yql)
baseurl='http://query.yahooapis.com/v1/yql'
YQLget2legged(baseurl, yql)
print 'Done.'
And the output
CODE
$ /usr/local/python-2.5.2/bin/python YQLtest.py
parameters: {'q': 'show tables', 'format': 'xml'}
Create Consumer
Create Request
Sign Request
Execute Request
Headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Accept': '*', 'Authorization': 'OAuth realm="", oauth_version="1.0", oauth_nonce="53180138", oauth_timestamp="1234791187", oauth_signature="[hidden]%26", oauth_consumer_key="[hidden]", oauth_signature_method="PLAINTEXT"'}
URL: http://query.yahooapis.com/v1/yql?q=show%20tables&oauth_version=1.0&oauth_nonce=53180138&oauth_timestamp=1234791187&oauth_signature=[hidden]%26&oauth_consumer_key=[hidden]&format=xml&oauth_signature_method=PLAINTEXT
Read Response
Params returned: <?xml version='1.0' encoding='UTF-8'?>
<yahoo:error xmlns:yahoo='http://yahooapis.com/v1/base.rng'
xml:lang='en-US'>
<yahoo:description>Please provide valid credentials</yahoo:description>
</yahoo:error>
<!-- yqlengine1.pipes.ch1.yahoo.com uncompressed/chunked Mon Feb 16 13:33:07 GMT 2009 -->
Done.
$
(Note: while editing the above to hide the key/secret I noticed that a %26 (ampersand) has been added to the oauth_signature. Could this be a ause of the problem?)