0

How to access YQL in Python (Django)?

Hey, I need a simple example for the following task:
Send a query to YQL and receive a response
I am accessing public data from python backend of my Django app.

If I just copy/paste an example from YQL, it says "Please provide valid credentials".
I guess, I need OAuth authorization to do it.
So I got an API key and a shared secret.

Now, what should I do with them?
Should I use python oauth library? This one?
http://oauth.googlecode.com/svn/code/python/oauth/

But what is the code? How I pass my secret/API key along with my yql query?

I guess, many Django programmers would love to know this.

by
2 Replies
  • Ok, I resolved the problem.

    In YQL console example for data/html the following url was presented as an example:

    http://query.yahooapis.com/v1/yql?q=select...Ful%2Fli%2Fa%27

    It does not work!
    But if you insert "/public" after "v1/" than it magically starts working!

    http://query.yahooapis.com/v1/public/yql?q...Ful%2Fli%2Fa%27


    YQL guys, maybe you should fix your examples!



    But the question of how to pass my API key (for v1/yql access) is still open. Any advice?
    0
  • QUOTE (Yury Lifshits @ Oct 3 2009, 11:05 AM) <{POST_SNAPBACK}>
    Ok, I resolved the problem.

    In YQL console example for data/html the following url was presented as an example:

    http://query.yahooapis.com/v1/yql?q=select...Ful%2Fli%2Fa%27

    It does not work!
    But if you insert "/public" after "v1/" than it magically starts working!

    http://query.yahooapis.com/v1/public/yql?q...Ful%2Fli%2Fa%27


    YQL guys, maybe you should fix your examples!



    But the question of how to pass my API key (for v1/yql access) is still open. Any advice?



    See the python sdk for yahoo apis: http://github.com/yahoo/yos-social-python


    simple examples in readme:

    CODE
    import yahoo.yql

    response = yahoo.yql.YQLQuery().execute('select * from delicious.feeds.popular')
    if 'query' in response and 'results' in response['query']:
    print response['query']['results']
    elif 'error' in response:
    print 'YQL query failed with error: "%s".' % response['error']['description']
    else:
    print 'YQL response malformed.'


    CODE
    import yahoo.application

    # Yahoo! OAuth Credentials - http://developer.yahoo.com/dashboard/

    CONSUMER_KEY = '##'
    CONSUMER_SECRET = '##'
    APPLICATION_ID = '##'
    CALLBACK_URL = '##'

    oauthapp = yahoo.application.OAuthApplication(CONSUMER_KEY, CONSUMER_SECRET, APPLICATION_ID, CALLBACK_URL)

    # Fetch request token
    request_token = oauthapp.get_request_token(CALLBACK_URL)

    # Redirect user to authorization url
    redirect_url = oauthapp.get_authorization_url(request_token)

    # Exchange request token for authorized access token
    verifier = self.request.get('oauth_verifier') # must fetch oauth_verifier from request

    access_token = oauthapp.get_access_token(request_token, verifier)

    # update access token
    oauthapp.token = access_token

    profile = oauthapp.getProfile()

    print profile
    0
  • I just want to find out a way to get the historic data of price of certain commodities to draw graph automatically

    0

Recent Posts

in YQL