当尝试使用v2中的刷新令牌尝试获取新的访问令牌时,我现在收到一个非常长的令牌,看起来像某种加密密钥。最初,它只是一个与refresh_token几乎相同长度的直接access_token。现在这是在代表客户发送优步请求时使用的新access_token吗?或者我如何检索我应该在我的优步请求中使用的实际access_token,即曾经与刷新令牌几乎相同的那个。
下面是我使用Postman的回复的截图。
以下是调用access_token的C#sourcecode片段方法。
public async Task WebServerAsyncRefresh(string clientId, string clientSecret, string redirectUri, string RefreshToken)
{
if (string.IsNullOrEmpty(clientId)) throw new ArgumentNullException("clientId");
if (string.IsNullOrEmpty(clientSecret)) throw new ArgumentNullException("clientSecret");
if (string.IsNullOrEmpty(redirectUri)) throw new ArgumentNullException("redirectUri");
if (string.IsNullOrEmpty(RefreshToken)) throw new ArgumentNullException("refreshToken");
if (!Common.IsValidUri(redirectUri)) throw new ArgumentException("Invalid redirectUri");
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "refresh_token"),
new KeyValuePair<string, string>("client_id", clientId),
new KeyValuePair<string, string>("client_secret", clientSecret),
new KeyValuePair<string, string>("redirect_uri", redirectUri),
new KeyValuePair<string, string>("refresh_token", RefreshToken)
});
var request = new HttpRequestMessage()
{
Method = HttpMethod.Post,
RequestUri = new Uri(TokenUrl),
Content = content
};
var responseMessage = await _httpClient.SendAsync(request).ConfigureAwait(false);
var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
if (responseMessage.IsSuccessStatusCode)
{
var authToken = JsonConvert.DeserializeObject<AuthToken>(response);
AccessToken = authToken.access_token;
RefreshToken = authToken.refresh_token;
}
else
{
//TODO: Create appropriate error response
//var errorResponse = JsonConvert.DeserializeObject<AuthErrorResponse>(response);
//throw new ForceAuthException(errorResponse.error, errorResponse.error_description);
throw new Exception("error");
}
}