Neumayer Neumayer - 1 year ago 497
JSON Question

How to get a Yelp Fusion API access token?

I'm using the Yelp's Fusion API.

All the documentation is here and seems straight forward but still doesn't seem to work.

Here is my request for a token. OAuth2&client_secret= SECRET&client_id=ID

I receive this response.

"error": {
"description": "Bad Request",
"code": "CLIENT_ERROR"

I reread the documentation and it says

"To get an access token, make a POST call to the following endpoint
using the client id and secret obtained from the former step. Then get
the access token from the response body."

I submitted this SECRET

I got the same error.

What am I missing?

Thank you in advance

Answer Source

How to Send an Ajax request to Yelp using the Yelp API 2.0 with JavaScript?

The reason I'm answering my own question is because Yelp fusion didn't work for my application and 2.0 did. There isn't a lot of good information on the topic and I don't want new developers to be as frustrated as I was.

You need the following for the code to work.

Yelp API 2.0 Access

JQuery Library

-OAuth-Signature-js Library


function nonce_generate() {
  return (Math.floor(Math.random() * 1e12).toString());

var yelp_url = '' + 'search/';

    var parameters = {
      oauth_consumer_key: 'x', //consumer key
      oauth_token: 'x', // Token
      oauth_nonce: nonce_generate(),
      oauth_timestamp: Math.floor(,
      oauth_signature_method: 'HMAC-SHA1',
      oauth_version : '1.0',
      callback: 'cb',
      term:  'tacos',
      location: 'Wheeling,Il'          // This is crucial to include for jsonp implementation in AJAX or else the oauth-signature will be wrong.
                                                                                    //Consumer Secret    //Token Secret
    var encodedSignature = oauthSignature.generate('GET',yelp_url, parameters, 'x', 'x');
    parameters.oauth_signature = encodedSignature;

    var settings = {
      url: yelp_url,
      data: parameters,
      cache: true,                // This is crucial to include as well to prevent jQuery from adding on a cache-buster parameter "_=23489489749837", invalidating our oauth-signature
      dataType: 'jsonp',
      success: function(results) {
      error: function() {
        // Do stuff on fail
enter code here
    // Send AJAX query via jQuery library.



Script order matters when embedding links in the HTML.

This script order worked for this code.

<script src="lib/jquery-3.1.1.min.js"></script>
<script src="lib/oauth-signature.js"></script>
<script src="app.js"></script>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download