![](/img/trans.png)
[英]Trouble using cURL with Google Apps Script Web App in a PHP file
[英]PHP Curl Translation to Google App Script Fetch URL
我有以下工作的PHP代码调用API。 API将使用一些标头并加密它们以与Client-Signature
进行比较, Client-Signature
也是标头中的一个项目。
我翻译成了Google App Script。 但不幸的是,我收到了App Script代码的签名错误。
我的问题是,Google App Script会在显示的PHP代码中以相同的方式呈现标题吗? 因为排除了所有其他问题,我怀疑在HTTP请求中呈现标头的方式可能导致签名问题。
如果您发现其他问题,请告诉我。 我完全被困在这里。
$requestId = "**";
$tokenID = "**";
$signature = "**";
$ch = curl_init();
$url = "https://public-api.sandbox.bunq.com/v1/user/3079/monetary-account";
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
"Cache-Control: no-cache",
"Content-Type: application/json",
"User-Agent: VBA-Web v4.1.5 (https://github.com/VBA-tools/VBA-Web)",
"X-Bunq-Geolocation: 0 0 0 0 NL",
"X-Bunq-Language: en_US",
"X-Bunq-Region: en_US",
"X-Bunq-Client-Request-Id: " . $requestId,
"X-Bunq-Client-Authentication: " . $tokenID,
"X-Bunq-Client-Signature: " . $signature
];
var_dump( $headers);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
var_dump ( $server_output) ;
Google App脚本代码:
var requestId = "**";
var url = "https://public-api.sandbox.bunq.com/v1/user/3079/monetary-account";
var tokenID = "**";
var signature = "**";
var RequestHeader = {
"Cache-Control" : "no-cache",
"Content-Type" : "application/json" ,
"User-Agent" : "VBA-Web v4.1.5 (https://github.com/VBA-tools/VBA-Web)",
"X-Bunq-Geolocation" : "0 0 0 0 NL",
"X-Bunq-Language" : "en_US",
"X-Bunq-Region" : "en_US",
"X-Bunq-Client-Request-Id" : requestId,
"X-Bunq-Client-Authentication" : tokenID,
"X-Bunq-Client-Signature" : signature
};
var options = {
"method": "GET",
"headers": RequestHeader,
muteHttpExceptions : true
}
var response = UrlFetchApp.fetch(url, options);
Logger.log(response );
谢谢大家的建议。 创建一个Web服务,打印它收到的标头并发现它。
无论您在fetch方法中使用User-Agent放置什么,Google App Script都会显示自己的User-Agent值。 UrlFetchApp.getRequest不显示用户代理值到Web服务的内容。 它只显示你输入的内容。
所以在这种情况下,我在标题中放置了User-Agent的值:
VBA-Web v4.1.5( https://github.com/VBA-tools/VBA-Web )
getRequest
在标题中显示User-Agent的值以下:
VBA-Web v4.1.5( https://github.com/VBA-tools/VBA-Web )
当请求到达下面的Web服务时,User-Agent的标题中包含的内容如下:
Mozilla / 5.0(兼容; Google-Apps-Script)
由于User-Agent用于计算签名,因此我收到了签名错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.