Yelp still uses OAuth 1.0 for authenticating - https://www.yelp.com/developers/api_console. I've taken a stab at utilizing the yelp API to pull information into a simple test I'm conducting. A search for food and city and pull in the JSON information. There's virtually no information on this process except for an attempt in 2013 by Steve Yaus - https://stevenyau.wordpress.com/2013/08/29/accessing-the-yelp-api-with-oauth-within-unity/ Which utilizes an OauthBase.cs script to assist with key, and token signature generation. The problem is that the OauthBase group repository isn't properly maintained anymore -https://code.google.com/p/oauth/. Anyway, I went ahead and updated the original script to reflect what all the contributors indicated as bugs along with replacing the HTTP stuff with WWW class. To my knowledge this is the most up to date OauthBase script. Yelp has C# sample code - https://www.yelp.com/developers/documentation/v2/examples but the libraray references are .NET compatible and not compatible with Unity ( SimpleOauth.net in addition to newtonsoft.JSON.net - Can't find a single DLL or nuget package to come into Monodevelop) Anyway, I feel that I'm razor thin of getting it to work but I'm getting the follow Error - "INVALID_SIGNATURE", "description": "Invalid signature. Expected signature base string: GET\u..." It's clearly an issue with the the generation method, just can't figure it out/troubleshoot it. I would definitely appreciate some feedback, and please feel free to try it out yourself. Just bring the scripts into your project, slap the "Yelp_BasicSearch.cs" script to any gameobject in your scene, and run the scene. It'll print out results in the console and as a text file on your desktop . You may need to do a quick Yelp Dev signup to get keys/tokens to test it- https://www.yelp.com/developers/api_console P.S. - Found this unrelated Oauth example with fitbit and unity in unityscript though - http://technicalartistry.blogspot.be/2015/07/oauth2-unity-and-month-of-cursing.html?m=1
I replied back on my blog post but just in case you can't see it: Try my Twitter version of the OAuth signature generation. I remember it being a lot stricter at the time so I had to rewrite the signature generation: https://bitbucket.org/gambitforhire...ileviewer=file-view-default#TwitterAPI.cs-151
Gambit_for_hire - you're the bomb! Thanks again for the mega quick response and pointing me in the right direction. I'll let you know how it goes.
Gambit_for_hire you are a huge lifesaver, I swear man. Your code hit it right on the money$$$$. I used about 98% of it to get yelp to work. I really only made updates to 4 areas of your code. 1. SearchTwitter_Coroutine Function - I changed the key value parameter pairs to {"term","food"},{"location",WWW.escapeurl("San Francisco, ca")} - clearly as a basic search run. 2. CreateSignature Function -I reordered the urlParamsDictionary parameters Alphabetically based on section 3 of this article I found - https://blog.nraboy.com/2014/11/understanding-request-signing-oauth-1-0a-providers/ 3. CreateAuthorizationHeaderParameter Function - I reordered the Authorization header parameters to follow suite with the order indicated in the the Oauth.net spec - http://oauth.net/core/1.0a/#anchor12 4. The Main URL link should be kept to the minimum - https://api.yelp.com/v2/search/ Ran it, and got results. Thanks again man. I'll definitely pay it forward.
Sorry for the late reply.. I forgot about that we started this conversation here. Glad to hear you got it working! If you could, can you submit a pull request/create a patch or even fork it please? I would be interested to grab your fixes.
Gambit_for_hire -Not a problem. I'm new to git and just signed up the other day. I'll create a repository and notify you when I get a chance. Do you have a git username so I can throw you props.
Thanks again man. It's up as a snippet on both Bitbucket and Github. https://bitbucket.org/snippets/OJ3D/apEbp/unity3d-yelp-api-and-oauth1a https://gist.github.com/OJ3D/c1bca60d4d705ee6535f
Is Yelp planning on OAuth2? Take a look at our OAuth2 asset:http://unity3dassets.com/oauth-overview-in-unity/
Chris- not to my knowledge. Thanks for the link. looks like a perfect option if they do implement 2.0
@OJ3D Thanks for sharing your snippet! Works awesome. I've got a search that brings me the best rated places in my area. This is my first time dabbling in all of the above (Oauth, WWW requests, JSON) What do you do with the results of the search? I'd like to filter out all the names and URLs of the restaurants in the results and pass them into clickable buttons. What are the words and methods that I should be researching to accomplish this?
Bridin - Glad it works. What you essentially receive is text that is structured in a JSON format. In order to read what you need, use SimpleJSON to parse the text file (Node) into a usable array - http://wiki.unity3d.com/index.php/SimpleJSON. Then create a loop routine to parse out what you need.
Thank you! So I am getting closer. And I'm stuck at an impasse. I found this: http://answers.unity3d.com/questions/648066/how-to-get-the-keys-of-a-dictionary-.html And now I get the console to tell me that it has regions, totals and businesses. I believe that means that I have found the key? Now I just need to take it a step further and get the business names from the key? Maybe?
I don't know anything about the key stuff. I looked into that link, I didn't mess around with that stuff. Look at the SimpleJSON example scenes and the c# code. That's how I got things to work. it's something along the lines like this: //ReadYelpJSON is the www.text you recieved--i.e the JSON node Code (CSharp): JSONArray yelpitems = (JSONArray)ReadYelpJSON["businesses"]; //<--you'll see the businesses is the top most node in the JSON text int YelpArrayLength = yelpitems.Count; //for loop routines //Initialize arrays of interest string [] ParsedMobileUrlText = new string[YelpArrayLength]; string [] ParsedRatingText = new string[YelpArrayLength]; //Define the Arrays for (int i = 0; i < YelpArrayLength; i++) { ParsedMobileUrlText=ReadYelpJSON ["businesses"] ["mobile_url"]; ParsedRatingText=ReadYelpJSON ["businesses"] ["rating"]; } //Wallah!Usable arrays are now defined Also, if you're confused on the structure of a JSON node, use this tool (http://jsonviewer.stack.hu/) it's f-in! awesome. Just slap the text you receive, paste it and it'll show you the break down of the JSON node
@OJ3D Hey there! Thank you for your generous script! I wanted to share what I created with it. http://forum.unity3d.com/threads/winner-is-dinner.396605/#post-2588695
I had some similar struggles implementing OAuth in Unity. In my case it was to communicate with the WooCommerce REST API. I created a simple library to perform the signature and request URL generation. You can read more about it here (code included): https://codetolight.wordpress.com/2017/01/16/oauth-for-woocommerce-in-unity3d/