Is it possible to use the Yahoo BOSS OAuth with JavaScript only?

284 Views Asked by At

Here is the problem, I have a Google Chrome extension and I want to use the BOSS API in it. The problem is that I do not know if it is possible to use the API without a webserver running.

The documentation does not provide any example using JavaScript. Thus my question:

Is it possible to use the Yahoo BOSS OAuth with JavaScript only?

2

There are 2 best solutions below

0
On

Probably not...

All the examples Yahoo provides are using server side languages

http://developer.yahoo.com/boss/search/boss_api_guide/codeexamples.html

First you'd have to figure out how to use OAuth with JavaScript, and how will you obscure your API keys from users in a JS File? If you don't have to worry about that, say you are just using this for personal use. Maybe check out the code sample for Node.JS and modify it for your own uses.

http://developer.yahoo.com/boss/search/boss_api_guide/codeexamples.html#oauth_js

function yahooSearch(consumerKey, consumerSecret, query, count,  
callback_error_data_response){  
 var webSearchUrl = 'https://yboss.yahooapis.com/ysearch/web';  

  var finalUrl = webSearchUrl + '?' + qs.stringify({  
    q: query,  //search keywords  
    format: 'json',  
    count: count,  
  });  

  var oa = new OAuth(webSearchUrl, webSearchUrl, consumerKey, consumerSecret, "1.0", null, "HMAC-SHA1");  
  oa.setClientOptions({ requestTokenHttpMethod: 'GET' });  
  oa.getProtectedResource(finalUrl, "GET", '','', callback_error_data_response);  
}  

// Use this function to make a call back. Make sure to provide the right key, secret and query for this to work correctly yahooSearch('YAHOO CONSUMER KEY GOES HERE', 'YAHOO CONSUMER SECRET GOES HERE', 'SEARCH QUERY', 10, function(error, data, response){  
// enter some code here and access the results from the "data" variable in JSON format  
});  
0
On

You can go to YQL Console and then enter your request, you can select Json or XML, after your result is fetched, look at the bottom of the page and then copy the url. You will be able to use that url inside script tags in an html doc and run it with your browser without a server.