Advertisement
luminousjj

nodejs_token_demo

Jul 4th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //获取用户认证token的NodeJs示例代码
  2. var request = require("request");
  3.  
  4. var options = { method: 'POST',
  5.   url: 'https://zx-api.juhe.cn/oauth2/token',
  6.   headers:
  7.    {'Content-Type': 'application/x-www-form-urlencoded' },
  8.  
  9.   //输入参数
  10.   //参数示例: "grant_type=client_credentials&client_id=<client_id>&client_secret=<client_secret>&scopes=carrier"
  11.   //<client_id>和<client_secret>在个人中心查看; scopes的值根据服务的不同自行切换; 参数也可使用表单提交
  12.  
  13.   form:
  14.    { grant_type: 'client_credentials',
  15.      client_id: 'c89fe53b39c3b52f1c6ec123456789',
  16.      client_secret: 'f53f1ad4dd2fbe1ffe9bf123456789',
  17.      scopes: 'carrier' } };
  18.  
  19. request(options, function (error, response, body) {
  20.   if (error) throw new Error(error);
  21.  
  22.   console.log(body);
  23. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement