作为查询参数传递的访问令牌在使用请求模块时变为无效

时间:2019-05-15 05:02:57

标签: javascript node.js contentful

我正在使用内容丰富的(CMS平台)api通过使用request模块通过userId获取用户详细信息。在此,访问令牌作为查询参数传递,系统将其视为无效参数。但是我不确定我传递查询参数的方式是否有错误,我很确定传递的令牌是有效的,因为我可以使用rest-client获得正确的结果。代码如下:

request.get(
  {
    url:
      "https://api.contentful.com/organizations/organizationId/users/userId",
    qs: {
      access_token:
        " CFPAT-xxxxxxxxxxxxxsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
    },
    headers: {
      Authorization:
        "CFPAT-xxxxxxxxxxxxxsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "x-contentful-enable-alpha-feature": "organization-user-management-api",
      "Content-Type": "application/json"
    },
    method: "GET",
    json: true
  },
  function(error, response, body) {
    console.log(body);
  }
);

Error:

{ requestId: 'e102c744950f39fdabad9ae942ac16ba',
  message:
   'The access token you sent could not be found or is invalid.',
  sys: { type: 'Error', id: 'AccessTokenInvalid' } }

0 个答案:

没有答案