嗨,当您尝试获取相册时,我得到401的未授权 这是在我已经成功之后。 但是过了一会儿,我猜测访问令牌已过期,需要刷新令牌。
我正在尝试刷新令牌
使用此URL = https://www.googleapis.com/oauth2/v4/token
我正在使用 client_secret, 刷新令牌, client_id, grant_type
但获得“无效的grant_type”?
var url =“ https://www.googleapis.com/oauth2/v4/token”;
using (var client = new HttpClient())
{
try
{
var postData = new
{
refresh_token = request.RefreshToken,
client_id = ClientId,
client_secret = ClientSecret,
grant_type = "refresh_token"
};
var content = new StringContent(JsonConvert.SerializeObject(postData));
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
HttpResponseMessage response = client.PostAsync(new Uri(url), content).Result;
if (response.IsSuccessStatusCode)
{
var token =await response.Content.ReadAsStringAsync();
//token as TokenResponse;
//return new OAuthDetails
//{
// AccessToken = token.AccessToken,
// Expires = token.Issued.AddSeconds(token.ExpiresInSeconds ?? 1800),
// RefreshToken = token.RefreshToken,
//};
return null;
// return await response.Content.ReadAsStringAsync();
}
return null;
}
catch (Exception ex)
{
return null;
}
}
有什么建议吗?