Open jakehockey10 opened 9 years ago
OAuth through Yelp is very difficult, and @peymanmortazavi has spent hours trying, but getting this to function may require building a whole node backend to make the calls.
Rumor has it that @develra has solved it. Care to chime in?
Thanks Dawson. I was somewhat leaning towards assuming starting from scratch was necessary. If Peyman hasn't figured it out yet, I'm a little scared, honestly...
Be afraid, be very afraid :ghost:
Heya,
Ya, I got it working. You are correct that you need a server-side service like node.js
You don't need to rewrite everything, just make a heroku app that takes your "real" parameters (like term and location) and then appends the rest of the O-auth stuff to it, get the response, then forwards the response back to your app, so like
You app --> node.js yelp-api-router --> real yelp API --> node.js yelp-api-router --> your app.
I have one (almost) put together people can use, but I don't know if that defeats the point of the assignment? I can ask Tom.
To make your own I used this library
https://github.com/olalonde/node-yelp
then express for the routing.
Here is a simply working example
var yelp = require("yelp").createClient({
consumer_key: "b8iV8U1TojhwQ2SLdpAkoQ",
consumer_secret: "q7Ghgx2gLh-qH-vNYmpLkUSueTQ",
token: "W2ia0PkM0POzY6K2CSaUrYv5XRINCThT",
token_secret: "PyHb46utgiZLhhDsR_36KWVSuKk"
});
// See http://www.yelp.com/developers/documentation/v2/search_api
yelp.search({term: "food", location: "Montreal"}, function(error, data) {
console.log(error);
console.log(data);
});
// See http://www.yelp.com/developers/documentation/v2/business
yelp.business("yelp-san-francisco", function(error, data) {
console.log(error);
console.log(data);
});
Hope that helps! Lemme know if you have any question
My appreciation of your support is overwhelming me right now. You are awesome.
A few final things-
I went ahead and hosted my very hacked-together version at
https://lit-bayou-6850.herokuapp.com/
for testing purposes.
You can search for stuff like
https://lit-bayou-6850.herokuapp.com/search/term=food&location=San+Francisco
and it will send you back the proper objects.
(Theoretically https://lit-bayou-6850.herokuapp.com/business/stuff works as well, but I haven't tried it out yet.)
A huge hint to those making this service themselves - there is a library called qs (short for query string) that does this very specific thing:
query = Qs.parse('term=food&location=San+Francisco');
// query === { term: 'food', location: 'San Francisco' }
it comes in pretty handy. GL;HF
Oh man. It turns out that when you said you used the node-yelp library, I just assumed that npm install node-yelp
would install the same thing into my express app. My client object wasn't getting created correctly because in trying both the node-yelp
and the yelp
node_modules, I was getting the format of the object you have to pass into createClient({...})
mixed up between the two node_modules. The examples you show above go with the node_module "yelp" and that is how I got it working.
Thank you so much for your help.
Hello all,
Our team had some issues getting up and running with authentication today when we had our team meeting. We have a consumer key, consumer secret, token, and token secret. But everything we tried either would fail authentication or just not compile. Is there an additional piece that needs to be added to our server set up beyond what we started with in the yelp-jquery assignment from before? We also tried installing known node modules for the yelp api, but the require statements didn't seem to work. Wintersmith is built on top of node.js, but is it "too client-side" to make these API calls? Would it be better to build a more server side node application from scratch?
Any suggestions/help would be great! Thanks!