2017-09-15 5 views
1

Yelp fusion APIにアクセスしようとしています。しかし、私のOVH VPSに私はこのエラーを取得しています、Yelp Fusion:トークンを取得できません

const request = require('request'); 

// As you can see the common error of there being a whitespace 
// in one of these is not the case here 
const clientId = 'O<removed>w'; 
const clientSecret = 'm<removed>r'; 

const options = { 
    url: 'https://api.yelp.com/oauth2/token', 
    method: 'POST', 
    headers: { 
     'Content-Type': 'application/x-www-form-urlencoded' 
    }, 
    json: { 
     'grant_type': 'client_credentials', 
     'client_id': clientId, 
     'client_secret': clientSecret 
    } 
}; 

request(options, (err, res, body) => { 
    if(err) { 
     return console.log(err); 
    } 
    console.log(body); 
}); 

私はこれと同じ呼び出しで正しい応答を取得していますAPIGeeを使用した:私はdocumentationを以下のこのコードに来ています(これはからのものであることに注意してください本文変数)

{ error: 
    { code: 'VALIDATION_ERROR', 
     description: 'client_id or client_secret parameters not found. Make sure to provide client_id and client_secret in the body with the application/x-www-form-urlencoded content-type' } } 

私は正しくコールを設定していると思います。誰かが正しい方向に私を向けることができますか?ありがとうございました!

+0

ルック(https://stackoverflow.com/questions/9870523/differences-in-application-json-and-application-x-www-form-urlencoded) –

+0

缶'content-type'で小文字でチェックしますか? – abdulbarik

+0

@abdulbarikうまくいきませんでした –

答えて

0

データを正しく送信するためのオプションを変更する必要があります。データはbodyフィールドに入ると、それは代わりに、あなたはまたjson:true

const options = { 
    url: 'https://api.yelp.com/oauth2/token', 
    method: 'POST', 
    body: { 
     'grant_type': 'client_credentials', 
     'client_id': clientId, 
     'client_secret': clientSecret 
    }, 
    json: true 
}; 

を設定する必要があり、文字列JSONオブジェクトの場合、私はヘッダが必要になるとは思いません。 [ここ]で

チェック要求options documentation

+0

私は今[this code](https://hastebin.com/hokexidixa.scala) を持っていて、私は[このエラー](https://hastebin.com/konifaxana)を取得しています。 vbs) リクエストライブラリにエラーがあるようです。ヘッダーセクションがなければ、私の元の投稿で言及したエラーが表示されます。何か案は?ありがとうございました –

関連する問題