Salesforce 营销云 API 没有 return access/authorization 令牌
Salesforce marketing cloud API does not return an access/authorization token
我有一个应用程序请求营销云获取访问令牌,以便在后续请求中使用以访问 API。这是去年设计的,直到上周都运行良好。自 02/22 以来,同一请求一直失败。以下是请求令牌的示例代码:
public static async Task<string> GetAuthorizationToken(string ClientId, string ClientSecret)
{
string strAuthorizationToken = string.Empty;
HttpClient client = new HttpClient();
var dictParams = new Dictionary<string, string>()
{
{ "clientId", ClientId }, {"clientSecret", ClientSecret }
};
var content = new FormUrlEncodedContent(dictParams);
var response = await client.PostAsync("https://auth.exacttargetapis.com/v1/requestToken", content);
if (response.IsSuccessStatusCode)
{
var strresponse = await response.Content.ReadAsStringAsync();
//dynamic objResult = JsonConvert.DeserializeObject<dynamic>(strresponse);
//strAuthorizationToken = objResult.accessToken;
}
return strAuthorizationToken;
}
GetAuthorizationToken("*********", "*******").GetAwaiter().GetResult();
这是我从 API:
得到的错误
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
X-Mashery-Responder: 02-26
Vary: Origin
X-Mashery-Message-ID: f4cec199-2e7e-49e2-88e0-6673ffe849ed
strict-transport-security: max-age=15552000; preload
Content-Security-Policy: upgrade-insecure-requests
x-xss-protection: 1; mode=block
x-frame-options: DENY
x-content-type-options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Connection: close
Cache-Control: no-store, must-revalidate, no-cache, max-age=0, private
Date: Tue, 26 Feb 2019 16:42:29 GMT
Server: Apache
Content-Length: 223
Content-Type: application/json; charset=UTF-8
}}
我需要知道此代码中发生了什么变化或我需要修复什么才能再次访问 API。请帮助我如何再次完成这项工作。
提前致谢。
我发布的是已解决的答案,可能对发送 HTTP 请求时遇到类似问题的其他人有所帮助。
我必须添加以下代码行来指定要使用的安全协议:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;
我有一个应用程序请求营销云获取访问令牌,以便在后续请求中使用以访问 API。这是去年设计的,直到上周都运行良好。自 02/22 以来,同一请求一直失败。以下是请求令牌的示例代码:
public static async Task<string> GetAuthorizationToken(string ClientId, string ClientSecret)
{
string strAuthorizationToken = string.Empty;
HttpClient client = new HttpClient();
var dictParams = new Dictionary<string, string>()
{
{ "clientId", ClientId }, {"clientSecret", ClientSecret }
};
var content = new FormUrlEncodedContent(dictParams);
var response = await client.PostAsync("https://auth.exacttargetapis.com/v1/requestToken", content);
if (response.IsSuccessStatusCode)
{
var strresponse = await response.Content.ReadAsStringAsync();
//dynamic objResult = JsonConvert.DeserializeObject<dynamic>(strresponse);
//strAuthorizationToken = objResult.accessToken;
}
return strAuthorizationToken;
}
GetAuthorizationToken("*********", "*******").GetAwaiter().GetResult();
这是我从 API:
得到的错误{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
X-Mashery-Responder: 02-26
Vary: Origin
X-Mashery-Message-ID: f4cec199-2e7e-49e2-88e0-6673ffe849ed
strict-transport-security: max-age=15552000; preload
Content-Security-Policy: upgrade-insecure-requests
x-xss-protection: 1; mode=block
x-frame-options: DENY
x-content-type-options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Connection: close
Cache-Control: no-store, must-revalidate, no-cache, max-age=0, private
Date: Tue, 26 Feb 2019 16:42:29 GMT
Server: Apache
Content-Length: 223
Content-Type: application/json; charset=UTF-8
}}
我需要知道此代码中发生了什么变化或我需要修复什么才能再次访问 API。请帮助我如何再次完成这项工作。 提前致谢。
我发布的是已解决的答案,可能对发送 HTTP 请求时遇到类似问题的其他人有所帮助。
我必须添加以下代码行来指定要使用的安全协议:
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;