Mohamed Hussain
Mohamed Hussain

Reputation: 7703

Yahoo OAuth authorization issue when implementing the yahoo search in my site using node.js

I tried to use the OAuth for yahoo search. I am new to this concept.

I registered in yahoo and got consumer and secret key.

I implemented it using JavaScript, when I test my code (test.js) using node.js(i installed npm install oauth –g) i got the following error instead of XML.

{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }

TEST.JS

var OAuth = require('oauth').OAuth;
var key = 'dj0yJmk9cU5GT2p5T0VRc3R2JmQ9WVdrOVZHeFZaR1YwTjJFbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1lYg--';
var secret = 'e766c8cbd1c7b31612b1787e1f39b7b27a88433d';
var webSearchUrl = 'https://ysp.yahooapis.com/ysp/web';
var finalUrl = webSearchUrl + '?q=iphone';
var oa = new OAuth(webSearchUrl, webSearchUrl, key, secret, "1.0", null, "HMAC-SHA1", null, {"Accept-Language": null, "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "User-Agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:30.0) Gecko/20100101 Firefox/30.0", "Cookie" : ""});
oa.setClientOptions({ requestTokenHttpMethod: 'GET' });
oa.get(finalUrl, '','', function (error, data, resp) {
    if (error || resp.statusCode !== 200) { // if there is a error, exit with error message
        return console.log(error);
    } 
    // otherwise, echo incoming data
    console.log(data);
});

enter image description here

Please help me in this to get the XML data for processing. Thanks in advance for any help.

Update to the Question

After trying the implementation in the link given by michaelchum in test.js I go the following error PFA SS and test2.js code.

Test2.js

var YaBoss = require('yaboss');
var YaBossClient = new YaBoss('someCustomerKey', 'someCustomerSecret');

YaBossClient.search('web','yahoo', {count: 10}, function(err,dataFound,response){
    console.log("Data :*****");
    console.log(dataFound);
    console.log("Error :*****");
    console.log(err);
});

enter image description here

Upvotes: 0

Views: 397

Answers (1)

Michael Ho Chum
Michael Ho Chum

Reputation: 939

This is because the Yahoo Search BOSS API requires OAuth1.0A, you've selected OAuth1.0 in your OAuth library call.

There is actually a Yahoo Search API npm package, you should take a look, it will make the implementation much easier.

Try this:

Make a new folder and a new file app.js

var YaBoss = require('yaboss');

var key = 'dj0yJmk9cU5GT2p5T0VRc3R2JmQ9WVdrOVZHeFZaR1YwTjJFbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1lYg--';
var secret = 'e766c8cbd1c7b31612b1787e1f39b7b27a88433d';

var YaBossClient = new YaBoss(key, secret);

YaBossClient.search('web','yahoo', {count: 10}, function(err,dataFound,response){
    console.log("Data :*****");
    console.log(dataFound);
    console.log("Error :*****");
    console.log(err);
});

In the folder do npm install yaboss and then node app.js

Upvotes: 1

Related Questions