引用错误:对象赋值中的左侧无效
ReferenceError: Invalid left-hand side in assignment at Object
试图完成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();
});
});
这不是有效的 JavaScript 语法:
body: client_id=buffer_clientid&client_secret=buffer_secret&redirect_uri=redirectURI&code=tokencode&grant_type=authorization_code
我假设您正在尝试将变量值连接到字符串?试试这个:
body: "client_id=" + buffer_clientid + "&client_secret=" + buffer_secret + "&redirect_uri=" + redirectURI + "&code=" + tokencode + "&grant_type=" +authorization_code
nodejs 中的字符串需要用引号括起来。在你的请求函数中,你传递了一个 body 键,其值似乎是一个巨大的变量。因为client_id=buffer_clientid&client_secret=buffer_secret&redirect_uri=redirectURI&code=tokencode&grant_type=authorization_code
周围没有引号,所以它试图将其视为一个变量。当解析器到达=
符号时,它会尝试设置 client_id = 以下内容。这是抛出错误。
只需引用整个字符串,或者如果您需要使用变量 concat 使用 'string' + variable + 'string'
.
从您的变量名称来看,您可以简单地重写如下:
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();
})
相关文章:
- 未捕获的ReferenceError:赋值中的左侧无效
- 变量赋值无效
- Javascript/Html 未捕获的引用错误:赋值中的左侧无效;未捕获的引用错误:未定义计算
- 样式属性赋值上的“赋值中的左侧无效”
- 左侧赋值无效(railo.transformer.bytecode.op.OpString)
- 在javascript中构建HTML表,得到“引用错误:左侧无效赋值”
- 更改 CSS“z-index”属性:“赋值中的左侧无效”
- Javascript 错误:左侧赋值无效
- 在引用错误中将字符串放在一起:左侧的赋值无效
- 未捕获的引用错误:赋值(匿名函数)中的左侧无效
- jQuery/Javascript赋值左侧无效
- 为innerHTML赋值无效
- 带有三进制if的左侧赋值无效
- 在我必须做的一件简单的事情中,赋值中的左侧无效
- "赋值中的左侧无效“;当接收到来自Facebook API的响应时
- 我得到了“;赋值中的左侧无效“;在我的代码(JS)中
- 变量名称-赋值中左侧无效
- 未捕获的ReferenceError:赋值javascript中的左侧无效
- 如何处理'无效赋值left hand '错误:firefox或chrome
- Javascript ReferenceError:左边无效赋值