首页 > 解决方案 > 邮递员脚本设置环境变量

问题描述

我正在为 API 与我们的服务集成之一创建一个邮递员集合。这里我们使用 OAuth1.0 进行身份验证。我想将 oauth 初始化响应oauth_tokenoauth_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,而不是本机应用程序。

标签: postman

解决方案


在您需要使用的 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


推荐阅读