有効期限が切れたアクセス トークンを更新できません。何が悪いのかわからないので、ドキュメントに従って実行しました。WCF サービスを使用していますが、以下のエラーが発生します。
{StatusCode: 400、ReasonPhrase: 'Bad Request'、バージョン: 1.1、コンテンツ: System.Net.Http.StreamContent、Headers: { Connection: keep-alive
x-frame-options: SAMEORIGIN X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" CF -RAY: 4294254a0b608a9d-BOM Cache-Control: no-store Date: Mon, 11 Jun 2018 12:40:21 GMT Set-Cookie: __cfduid=d9ac433a81ce1ec1aedad217862472b131528720820; 有効期限=2019 年 6 月 11 日火曜日 12:40:20 GMT; パス=/; ドメイン=.lightspeedapp.com; HttpOnly; セキュア サーバー: cloudflare Content-Length: 69 Content-Type: application/json }}
public string RefreshToken(string clientsecretkey, string clientkey, string refreshToken)
{
string newToken = "";
int expTime = 0;
string scope = "";
string type = "";
try
{
using (var client = new HttpClient())
{
using (var content = new MultipartFormDataContent())
{
var values = new[]
{
new KeyValuePair<string, string>("refresh_token", refreshToken),
new KeyValuePair<string, string>("client_id",clientkey),
new KeyValuePair<string, string>("client_secret",clientsecretkey),
new KeyValuePair<string, string>("grant_type", "refresh_token")
};
foreach (var keyValuePair in values)
{
content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);
}
var fileContent = new ByteArrayContent(new byte[100]);
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "Foo.txt"
};
content.Add(fileContent);
var requestUri = "https://cloud.lightspeedapp.com/oauth/access_token.php";
HttpResponseMessage result = client.PostAsync(requestUri, content).Result;
if (result.StatusCode == HttpStatusCode.OK)
{
var smessage = result.Content.ReadAsAsync<UserCredentials>(new[] { new JsonMediaTypeFormatter() }).Result;
if (smessage != null)
{
newToken = smessage.AccessToken;
expTime = smessage.ExpiresIn;
scope = smessage.Scope;
type = smessage.TokenType;
}
}
}
}
}