【问题标题】:I want to get Stex.com API access token我想获得 Stex.com API 访问令牌
【发布时间】:2019-07-02 04:44:25
【问题描述】:

我正在开发 C# WinForms 应用程序以在 Stex.com 上进行交易。 他们将 api 升级到 api3。 它使用谷歌身份验证应用程序登录。 这就是为什么没有人的行为就无法获得访问令牌的原因。 最后决定用postman来获取access token,并且想在token过期的时候刷新token。

我认为这是最好的方法。 所以我通过邮递员获得了访问令牌和刷新令牌。 https://help.stex.com/en/articles/2740368-how-to-connect-to-the-stex-api-v3-using-postman.

现在该刷新我的令牌了。 所以这是我写的。

string refresh_token = "def50200b03974080...";
string client_id = "502";
string client_secret = "SeTs50aFxV1RoMFBW1b4RVNQhh2wEdICaYQrpE3s";
string AccessToken = "eyJ0eXAiOiJKV1QiLCJhbGciO...";
string url = @"https://api3.stex.com/oauth/token";
var request = HttpWebRequest.Create(url);
            request.Method = "POST";
            request.Headers.Add("Authorization", "Bearer " + AccessToken);
            request.ContentType = "application/x-www-form-urlencoded";
 NameValueCollection outgoingQueryString = HttpUtility.ParseQueryString(String.Empty);
            outgoingQueryString.Add("grant_type", "refresh_token");
            outgoingQueryString.Add("refresh_token", refresh_token);
            outgoingQueryString.Add("client_id", client_id);
            outgoingQueryString.Add("client_secret", client_secret);
            outgoingQueryString.Add("scope", "trade profile reports");
            outgoingQueryString.Add("redirect_uri", @"https://www.getpostman.com/oauth2/callback");

byte[] postBytes = new ASCIIEncoding().GetBytes(outgoingQueryString.ToString());

Stream postStream = request.GetRequestStream();
            postStream.Write(postBytes, 0, postBytes.Length);
            postStream.Flush();
            postStream.Close();

using (WebResponse response = request.GetResponse())
{
    using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
    {
        dynamic jsonResponseText = streamReader.ReadToEnd();
     }
}

显示 401(未授权)错误。 当我删除 ContentType 时,它​​显示 400(Bad Request) 错误。 如果有人这样做,请帮助我。

【问题讨论】:

    标签: c#


    【解决方案1】:

    伙计们! 最后,我发现了这个问题。 这个问题是由于我的无知。 遇到问题时冷静下来,放松一下。 :) 我创建了 2 个 api3 客户端,因此 client_secret 不同。 谢谢。

    【讨论】:

    • 如果有人对此有任何疑问,请与我联系。希望能帮到你。:)
    猜你喜欢
    • 2017-06-09
    • 1970-01-01
    • 2013-12-09
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 1970-01-01
    • 2015-05-29
    相关资源
    最近更新 更多