首页 > 解决方案 > 无法为 Salesforce Marketing Cloud 令牌交换“代码”

问题描述

我正在尝试根据此处的文档交换 Salesforce Marketing Cloud (SFMC) authorization_codeaccess_tokenhttps: //developer.salesforce.com/docs/atlas.en-us.mc-app-development.meta/mc-app-development /access-token-app.htm

curl https://{my_subdomain}.auth.marketingcloudapis.com/v2/token \
  --request POST  \
  --header "Content-Type: application/json" \
  --data '{"grant_type": "authorization_code", "code": "{{my_code}}", "client_id": "{{my_client_id}}", "redirect_uri": "https://127.0.0.1:80/", “client_secret: “{{my_client_secret}}”, "scope": "audiences_read list_and_subscribers_write offline"}'

然而它不断地给我以下错误:

{"documentation":"https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/error-handling.htm","errorcode":0,"message":"Bad Request"}%

我不知道我哪里出错了,感谢任何帮助。

当我使用过期的和/或错误的时候,我看到了“正确”codeclient_id错误client_secret,但是在我粘贴了正确的值之后什么都没有。也许这是我的范围?

根据错误代码中链接的文档,The token was not found in the request, or it is invalid or expired.. 这是唯一具有customcode == 0. 这很奇怪,因为我试图获取 a token,而不是传递一个,并且该错误代码与 a 相关联401,这可能是也可能不是我收到的内容。

标签: salesforce-marketing-cloud

解决方案


原来我client_secret在我的数据中使用了不正确的双引号。这是一个倾斜的双引号。当我尝试使用Python3而不是cURL将上面的 JSON 转换为 JSON 以传递给requests库时,我发现了这一点。我能够成功获得令牌。

所以答案是,以上是正确的,只要注意你的编码!


推荐阅读