2016-07-07 3 views
1

OAuth2フローを終了しようとしましたが、キャッチされていない参照エラーが引き続き発生しました。 Node.jsとcantの新機能は、何が起こっているのかを見ているようです。私はあなたが文字列にあなたの変数の値を連結しようとしていると仮定していReferenceError:オブジェクトの代入で左辺が無効

body: client_id=buffer_clientid&client_secret=buffer_secret&redirect_uri=redirectURI&code=tokencode&grant_type=authorization_code 

:有効なJavaScriptシンタックスではありません

// require the blockspring package. 
var blockspring = require('blockspring'); 
var request = require('request'); 

// pass your function into blockspring.define. tells blockspring what function to run. 
blockspring.define(function(request, response) { 

    // retrieve input parameters and assign to variables for convenience. 
    var buffer_clientid = request.params["buffer_clientid"]; 
    var buffer_secret = request.params["buffer_secret"]; 
    var redirectURI = request.params["redirectURI"]; 
    var tokencode = request.params["tokencode"]; 


    request({ 
     method: "POST", 
     url: "https://api.bufferapp.com/1/oauth2/token.json", 
     headers: { 
     'User-Agent': 'request', 
     }, 
     body: client_id=buffer_clientid&client_secret=buffer_secret&redirect_uri=redirectURI&code=tokencode&grant_type=authorization_code 

    }, function(error, response, body){ 
     console.log(body); 

     // return the output. 
     response.end(); 
    }); 
}); 
+1

をあなたの 'body'データの前後に引用符を配置する必要があります。 'client_id = buffer ...'は文字列でなければなりません。存在しない 'client_id'に何かを割り当てようとしています。 –

+0

要求オブジェクト内の本体キーを文字列としてフォーマットする必要があります。あなたは '' string '+ variable +' string''を使って連結する必要があります – FrankerZ

答えて

1

?これを代わりに試してください:

body: "client_id=" + buffer_clientid + "&client_secret=" + buffer_secret + "&redirect_uri=" + redirectURI + "&code=" + tokencode + "&grant_type=" +authorization_code 
0

nodejsの文字列を引用符で囲む必要があります。あなたのリクエスト関数では、本体のキーを渡しています。その値は、巨大変数のように見えます。 client_id=buffer_clientid&client_secret=buffer_secret&redirect_uri=redirectURI&code=tokencode&grant_type=authorization_codeの前後に引用符がないので、これを変数として扱おうとしています。パーサーが=の標識に到達すると、client_id =を次のように設定しようとしています。これはエラーをスローしています。

単純に文字列全体を引用するか、'string' + variable + 'string'を使用して変数concatを使用する必要がある場合は、

あなたの変数名から判断すると、あなたは簡単な書き換えができ、次のように:

request({ 
    method: "POST", 
    url: "https://api.bufferapp.com/1/oauth2/token.json", 
    headers: { 
    'User-Agent': 'request', 
    }, 
    body: 'client_id=' + buffer_clientid + '&client_secret=' + buffer_secret + '&redirect_uri=' + redirectURI + '&code=' + tokencode + '&grant_type=authorization_code' 

}, function(error, response, body){ 
    console.log(body); 

    // return the output. 
    response.end(); 
}) 
関連する問題