Replies: 4 comments 2 replies
-
Since this is all a URL encoded string, can you log the output of the POST URL? Should look just like: |
Beta Was this translation helpful? Give feedback.
-
I'm not using RestSharp, just the out of the box .NET HttpClient and System.Text.Json. This is my working code public async Task<EtsyTokenResponse> GetRefreshAccessTokenAsync(string refreshToken)
{
EtsyTokenResponse? token = null;
var formData = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("grant_type", "refresh_token"),
new KeyValuePair<string, string>("client_id", $"{clientId}"),
new KeyValuePair<string, string>("refresh_token", $"{refreshToken}")
};
HttpRequestMessage baseRequest = new(HttpMethod.Post, "https://api.etsy.com/v3/public/oauth/token");
baseRequest.Content = new FormUrlEncodedContent(formData);
var httpClient = httpClientFactory.CreateClient();
var request = httpClient.SendAsync(baseRequest);
using (var response = await request)
{
string responseString = await response.Content.ReadAsStringAsync();
token = JsonSerializer.Deserialize<EtsyTokenResponse>(responseString);
}
return token!;
} And the EtsyTokenResponse model public class EtsyTokenResponse
{
[JsonPropertyName("access_token")]
public string AccessToken { get; set; }
[JsonPropertyName("token_type")]
public string TokenType { get; set; }
[JsonPropertyName("expires_in")]
public long ExpiresIn { get; set; }
[JsonPropertyName("refresh_token")]
public string RefreshToken { get; set; }
} |
Beta Was this translation helpful? Give feedback.
-
Hi guys thanks for the approaches! For the first I used:
response: But as the second is a as is working code, im still getting: I verified again, the token works when e.g. updating a listing. |
Beta Was this translation helpful? Give feedback.
-
Hi, |
Beta Was this translation helpful? Give feedback.
-
Hi guys,
i got basically everything working.. except .... getting a refresh token. I use rest sharp. I have tried approaches from different sources..
The token definitely works as i am using it elsewhere ..
I tried:
different headers but as i understand none are necessary.
add jsonbody and andbody with an anonymous object
addparameter
and another approach i found using dictionary and httpclient.
Everything I ever get is {"error":"invalid_grant","error_description":"refresh_token is invalid"}
Thanks!
i got basically everything working.. except .... getting a refresh token. I use rest sharp. I have tried approaches from different sources..
The token definitely works as i am using it elsewhere ..
I tried:
different headers but as i understand none are necessary.
add jsonbody and andbody with an anonymous object
addparameter with post and
public static RestResponse RefreshToken(string token)
{
Beta Was this translation helpful? Give feedback.
All reactions