ReferenceError:在Object的赋值中无效的左侧

时间:2016-07-07 20:25:52

标签: javascript node.js

尝试完成OAuth2流程,但不断获取未被捕获的引用错误。 Node.js相当新,似乎无法找出发生了什么。

// 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();
    });
});

2 个答案:

答案 0 :(得分:1)

这是无效的JavaScript语法:

$q

我假设您正在尝试将变量值连接到字符串?试试这个:

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

答案 1 :(得分:0)

需要引用nodejs中的字符串。在您的请求函数中,您传递了一个正文的密钥,其值似乎是一个巨大的变量。因为> with(df, as.character(X)!=as.character(Y))*1 [1] 0 1 0 1 周围没有引号,所以它会尝试将其视为变量。当解析器到达client_id=buffer_clientid&client_secret=buffer_secret&redirect_uri=redirectURI&code=tokencode&grant_type=authorization_code符号时,它会尝试设置client_id =以下内容。这就是错误。

只需引用整个字符串,或者如果需要使用=使用变量concat。

根据您的变量名称,您可以按如下方式简单地重写它:

'string' + variable + 'string'