var clientString = "<Client-id>" + ":" + "<client-secret>";
                byte[] clientEncode = Encoding.UTF8.GetBytes(clientString);
                var credentials = "Basic " + System.Convert.ToBase64String(clientEncode)

                HttpWebRequest request = WebRequest.Create("https://api.ebay.com/identity/v1/oauth2/token")
                    as HttpWebRequest;

                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";

                request.Headers.Add(HttpRequestHeader.Authorization, credentials);

                var codeEncoded = HttpUtility.UrlEncode(code);
               
                var body = "grant_type=authorization_code&code=" + codeEncoded + "&redirect_uri=" + "<return-url>";

                // Encode the parameters as form data
                byte[] formData = UTF8Encoding.UTF8.GetBytes(body);
                request.ContentLength = formData.Length;

                // Send the request
                using (Stream post = request.GetRequestStream())
                {
                    post.Write(formData, 0, formData.Length);
                }

                string result = null;
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)`

I am trying to get a OAuth User Access Token from the eBay API using this document: https://developer.ebay.com/api-docs/static/oauth-authorization-code-grant.html.

I am able to get authcode from ebay successfully. But while fetching token using auth code is giving me "the provided authorization grant code is invalid or was issued to another client".

I have added screen-shot of my c# code where i am trying to gettoken from auth code using authorization_code grant type.

C# code snippet

Strange thing is , same code is working correctly for sandbox credentials. It stopped working when i replaced prod credentials.

This is how i tried on postman but getting same error (https://i.stack.imgur.com/0LB4Y.png)

If i use oauth2 authorization in postman like below i am able to generate token

(https://i.stack.imgur.com/SYXlD.png)

Please help , i am new to ebay !

0

There are 0 best solutions below