【问题标题】:Square up retrieve merchant Id service endpoint not working as expected?Square up 检索商家 ID 服务端点未按预期工作?
【发布时间】:2016-01-28 08:36:37
【问题描述】:

根据 square up 的文档,在获得个人访问令牌后,我应该能够通过 curl 的简单请求来检索商家 ID。但是,我收到一个错误。如何获取商家 ID 而不是异常?

来自https://docs.connect.squareup.com

现在您可以使用您的个人访问令牌将您的第一个请求发送到 Connect API。

打开一个终端窗口并运行以下 curl 命令,在指示的位置提供您的个人访问令牌:

curl -H "Authorization: Bearer PERSONAL_ACCESS_TOKEN" https://connect.squareup.com/v1/me

文档中的预期结果:

{
  "id": "JGHJ0343",
  "name": "Dave Davis",
  "email": "dave@example.com",
  "country_code": "US",
  "language_code": "en-US",
  "business_name": "Dave's Milkshakes",
  "business_address": {
    "address_line_1": "1455 Market St",
    "locality": "San Francisco",
    "administrative_district_level_1": "CA",
    "postal_code": "94103"
  },
  "business_phone": {
    "calling_code": "+1",
    "number": "4155551234"
  },
  "business_type": "restaurants",
  "account_type": "LOCATION"
}

异常文本:

PS C:\Users\JMCC> curl -H "Authorization: Bearer PERSONAL_ACCESS_TOKEN" https://connect.squareup.com/v1/me
Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Authorization: Bearer PERSONAL_ACCESS_TOKEN" value of type "System.String" to type "System.Collections.IDictionary".
...

【问题讨论】:

  • 您已根据您的问题编辑了屏幕截图,因此现在它不可能对其他人有用。但是,评论历史仍然可以在 diff 中看到,因此您的个人访问令牌仍然是公开的。您需要生成一个新的个人访问令牌,这将使旧的无效。

标签: curl square-connect


【解决方案1】:

首先,您需要重新生成您的个人访问令牌,因为您已将其发布在公共论坛上。您可以在 connect.squareup.com 的开发者仪表板中执行此操作。

其次,文档假定您使用的是安装了cURL 命令行程序的机器。这是 Linux、Mac 和其他类 UNIX 机器上的常用实用程序。显然,Microsoft 已在较新版本的 PowerShell 中将 curl 设置为 Invoke-WebRequest cmdlet 的别名。我不确定他们为什么决定这样做,因为该命令的参数与 curl 提供的参数不兼容。

我建议在cURL download page 上获取 cURL 的 win64 版本。

【讨论】:

  • 有没有关于如何使用 OP 确定的方法来完成此任务的答案?
  • @driz 我猜你的意思是Invoke-RestMethod?如果是这样,我相信你可以做到,但你需要根据我链接的 PowerShell 文档翻译选项以匹配。不幸的是,我没有 Windows 机器来测试这个,但这样的东西可能会起作用:Invoke-RestMethod https://connect.squareup.com/v1/me -Headers @{"Authorization" = "Bearer ACCESS_TOKEN"}
  • 在我看来是Invoke-WebRequest 的别名,而不是Invoke-RestMethod: > get-alias curl CommandType Name ModuleName ----------- ---- - --------- 别名 curl -> Invoke-WebRequest
  • 嗯,你是对的。不知道我为什么写那个。无论如何,这两个命令看起来都非常相似。
猜你喜欢
  • 2022-08-17
  • 2014-04-08
  • 2019-06-02
  • 1970-01-01
  • 2016-01-29
  • 2017-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多