测试我的沙盒授权代码的说明是
如果使用的是Mac,请打开一个终端。如果使用Windows,请打开PowerShell会话。
1。通过将{{ACCESS_TOKEN}}替换为您的沙盒个人访问令牌来更新授权标头。
更新命令有效负载中的默认JSON块:
将idempotency_key设置为任何唯一的字符串,例如TESTKEY123。
将source_id设置为cnon:card-nonce-ok。
复制命令并将其粘贴到命令行中
运行命令
square提供的示例代码为:
$authHeader = @{ Authorization = 'Bearer {0}' -f "{{ACCESS_TOKEN}}" }
$body = '{
"idempotency_key": "{{UNIQUE-KEY}}",
"autocomplete": true,
"amount_money": {
"amount": 100,
"currency": "USD"
},
"source_id": "cnon:card-nonce-ok"
}
}'
Invoke-RestMethod -Uri https://connect.squareupsandbox.com/v2/payments |
-Method Post |
-ContentType "application/json" |
-Headers $authHeader |
-Body $body
该代码根本无法正常工作。如果我离开“ |”在Invoke-RestMethod中,我得到:
-Method:术语“ -Method”不被视为cmdlet,函数,脚本文件或可运行程序的名称。 检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。 在线:14字符:4 +-方法发布| + ~~~~~~~~ + CategoryInfo:ObjectNotFound:(-方法:字符串)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException
如果我把它们拿出来,我会得到:
Invoke-RestMethod:{“错误”:[{“代码”:“未经授权”,“详细信息”:“您的请求不包含带有标题的
Authorization
http标头 访问令牌。标头值应采用以下格式 \“ Bearer TOKEN \”(不带引号),其中TOKEN为 替换为您的访问令牌(例如\“ Bearer ABC123def456GHI789jkl0 \“)。有关更多信息,请参阅 https://docs.connect.squareup.com/api/connect/v2/#requestandresponseheaders。 如果您在使用我们的正式服务之一时看到此错误消息 支持的客户端库,请将此报告给 developers@squareup.com。 “,”类别“:” AUTHENTICATION_ERROR“}]}在 行:13字符:1 + Invoke-RestMethod -Uri https://connect.squareupsandbox.com/v2/payment ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[Invoke-RestMethod],WebExc 肽 + FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand -Method:术语“ -Method”不被视为cmdlet,函数,脚本文件或可运行程序的名称。检查拼写 的名称,或者如果包含路径,请验证路径是否为 更正并重试。在线:14字符:4 +-方法发布 + ~~~~~~~~ + CategoryInfo:ObjectNotFound:(-方法:字符串)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException-ContentType:术语“ -ContentType”不能识别为cmdlet,函数,脚本文件或可运行程序的名称。检查 名称的拼写,或者如果包含路径,请验证路径 是正确的,然后重试。在线:15字符:4 + -ContentType“ application / json” + ~~~~~~~~~~~~~ + CategoryInfo:ObjectNotFound:(-ContentType:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException
-Headers:术语“ -Headers”不被视为cmdlet,函数,脚本文件或可运行程序的名称。检查拼写 的名称,或者如果包含路径,请验证路径是否为 更正并重试。在线:16字符:4 +-标题$ authHeader + ~~~~~~~~~ + CategoryInfo:ObjectNotFound:(-Headers:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException
-Body:术语“ -Body”不被视为cmdlet,函数,脚本文件或可运行程序的名称。检查拼写 名称,或者如果包含路径,请确认路径正确,并 再试一次。在线:17字符:4 身体$ body + ~~~~~ + CategoryInfo:ObjectNotFound:(-Body:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException
我想念什么?这是我放入Powershell中的代码。我已经离开了沙盒授权,因此可以对其进行测试,以后我将进行更改。感谢您提供的任何帮助