locked
C# OAUTH2 TD Ameritrade POST RRS feed

  • Question

  • User-2004102533 posted

    I used the TD Ameritrade POST site to successfully get an access token. When I later put the same values in C# I get an invalid_grant response. What can cause that?

    Here is the C# code

    string url = string.Format("https://api.tdameritrade.com/v1/oauth2/token");
                RestClient client = new RestClient(url);
                RestRequest postRequest = new RestRequest(Method.POST);
                postRequest.AddHeader("cache-control", "no-cache");
                postRequest.AddHeader("content-type", "application/x-www-form-urlencoded");
                postRequest.AddParameter("application/x-www-form-urlencoded", "grant_type=authorization_code&access_type=offline&code= pMAPaM9nHYPUurvRxtnJXCINMAYP/1xDvZVEePiUFJYtsSldm88bVLxgf/f90XH653eEw8BbzE468HlZtgP4ph8igtGCFsTnyc/Z+N+CT/E=212FD3x19z9sWBHDJACbC00B75E&client_id=AMNEH3TUWFP@AMER.OAUTHAP&redirect_uri=http://localhost", ParameterType.RequestBody);
                IRestResponse response = client.Execute(postRequest); 

    Tuesday, September 3, 2019 7:31 PM

Answers

  • User1724605321 posted

    Hi DoctorWhoKnew,

    Check the response , do you find any inner detail error message returned from server ? You are using authorization_ code code flow , please also confirm that you have set correct code which returned from the previous code request .

    Best Regards,

    Nan Yu 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 4, 2019 2:13 AM

All replies

  • User1724605321 posted

    Hi DoctorWhoKnew,

    Check the response , do you find any inner detail error message returned from server ? You are using authorization_ code code flow , please also confirm that you have set correct code which returned from the previous code request .

    Best Regards,

    Nan Yu 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 4, 2019 2:13 AM
  • User-2004102533 posted

    I removed the access_type = offline. That was giving me a new refresh token each time.

    Wednesday, September 4, 2019 11:06 AM