1
我正在尝试使用Bitbucket的API从刷新密钥生成新的访问密钥。我可以成功地在终端中使用:Groovy的“execute”方法和正常运行bash命令有什么区别?
curl -X POST -u "${client_id}:${secretKey}" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d refresh_token=${refreshToken}
其中$ {...}已被其文字值替换。它正确返回与此类似:
{"access_token": "xxxxx", "scopes": "pullrequest", "expires_in": 3600, "refresh_token": "xxxxx", "token_type": "bearer"}
我使用Groovy执行此:
def getAccessToken = "curl -X POST -u \"${client_id}:${secret}\" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d refresh_token=${refreshToken}"
def getAccessTokenResult = getAccessToken.execute().text
当我的println命令和运行结果,将工作,所以它不是一个畸形URL。当我的println命令本身的结果,它回来了这一点:
{"error_description": "Invalid OAuth client credentials", "error": "unauthorized_client"}
没有理由这应该发生,除非有怎样的命令正在运行的根本区别,如果有人知道的区别或者甚至可以解决这个问题,我将非常感激。
您使用了大量shell变量中Groovy中的'curl'命令。当你运行Groovy代码时他们是否有价值? (很可能,你需要在运行之前导出它们,否则,实际运行的'curl'命令可能看起来像是'curl -X POST -u“:”https://bitbucket.org/site/oauth2/access_token -d grant_type = refresh_token -d refresh_token =' – chepner
@chepner在这里回答OP - 解析字符串是在执行之前完成的,getAccessToken的'println'显示正确填充所有值的完整'curl'命令;该命令可以粘贴到终端并直接运行(并给出我们期望的结果)。 –