postman - 邮递员脚本设置环境变量
问题描述
我正在为 API 与我们的服务集成之一创建一个邮递员集合。这里我们使用 OAuth1.0 进行身份验证。我想将 oauth 初始化响应oauth_token、oauth_token_secret设置为邮递员环境变量,以便我可以在进一步的请求中访问它们。响应采用以下格式而不是 JSON。 oauth_token= oauth_token_value &oauth_token_secret= oauth_token_secret_value &oauth_callback_confirmed=true
我尝试了以下脚本:
var output = require('querystring').parse(Response.text);
postman.setGlobalVariable("oauth_token", output.oauth_token);
postman.setGlobalVariable("oauth_token_secret", output.oauth_token_secret);
有人可以帮我将令牌设置为邮递员环境变量吗?
注意:我使用的是 chrome 插件版本 5.5.4,而不是本机应用程序。
解决方案
在您需要使用的 chrome 扩展中postman.setEnvironmentVariable()
:
postman.setEnvironmentVariable("oauth_token", output.oauth_token);
postman.setEnvironmentVariable("oauth_token_secret", output.oauth_token_secret);
为此,您需要创建并选择一个环境(无需手动添加任何变量)。如何做到这一点在这里描述:https ://learning.postman.com/docs/sending-requests/managing-environments/#creating-environments
推荐阅读
- python - 在 Python 中使用 ARN iam 将文件上传到 Amazon s3 存储桶
- c++ - 如何返回/复制 unique_ptr 的值
? - ruby-on-rails - 在heroku上通过捆绑安装本地gem不起作用
- ruby-on-rails - 尝试在 simple_from 中显示 Uppy 上传程序
- python - Python中的数据透视表
- aframe - 图像未在 A-Frame 版本 8 中显示(仅限版本 2)
- c - 为什么 main 使用返回类型字符串运行,即使它是用整数返回类型定义的?
- ocr - tesseract 4.0 未能检测到小于“<”符号
- java - Spring 框架和 html/xml 文件上的 Javadoc 示例/模板
- r - 为什么 seq() 同时创建 int 和 num 向量,而 c() 从不创建 int 向量?