question

sspl.user26_4 avatar image
0 Likes"
sspl.user26_4 asked

Error in getting user access token

I am working according to this doc [Getting a user access token][1] [1]: http://developer.ebay.com/Devzone/rest/ebay-rest/content/gen-user-token.html my code is as follows: const string url = " https://api.sandbox.ebay.com/identity/v1/oauth2/token"; string code = HttpUtility.UrlEncode(Request.QueryString["code"]); string data = "grant_type=authorization_code&code=" + code + "&redirect_uri=https%3A%2F%2Flocalhost%3A44300%2Febay"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Headers.Add("Authorization", getEncodetoBase64(ConfigurationManager.AppSettings["GemRareClientId"], ConfigurationManager.AppSettings["GemRareClientSecret"])); request.ContentLength = data.Length; using (Stream webStream = request.GetRequestStream()) using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII)) { requestWriter.Write(data); } try { WebResponse webResponse = request.GetResponse(); using (Stream webStream = webResponse.GetResponseStream()) { if (webStream != null) { using (StreamReader responseReader = new StreamReader(webStream)) { string response = responseReader.ReadToEnd(); JavaScriptSerializer serializer = new JavaScriptSerializer(); dynamic item = serializer.Deserialize
c# eaby api
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

stalin-1945 avatar image
0 Likes"
stalin-1945 answered
Same issue here. My code is: $url = sprintf(' https://api.sandbox.ebay.com/identity/v1/oauth2/token'); $request = $this->getHttpClient()->post($url, [ 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded', ], [ 'grant_type' => 'authorization_code', 'code' => $accessToken, 'redirect_uri' => 'https://localhost/checkout/decline', ]); $request->setAuth('App-ID', 'Cert-ID'); $response = $request->send(); $result = $response->json(); And the response is: { "error": "invalid_request", "error_description": "request is invalid", "error_uri": null }
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

aerendir-ita avatar image
0 Likes"
aerendir-ita answered
Me too using PHP and Guzzle... It seems that the page @sspl.user26_4 linked was moved to http://developer.ebay.com/Devzone/rest/ebay-rest/content/oauth-gen-user-token.html In that page, there is an error in the documentation too, as it is unclear if the parameters have to be passed via query string or via the body: the table has a caption that speaks about "OAuth token-request query parameters" but the column title is "Token Request Body Parameter": so, what has to be used? Query string or body? Anyway I've tried both, first using only body, then using only query string a third using both at the same time. Ever the same error: > {"error":"invalid_request","error_description":"request is invalid","error_uri":null} And I really don't know how to solve it. It seems not related to the language used. Instead it seems to be an internal error of the eBay API.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

stalin-1945 avatar image
1 Like"
stalin-1945 answered
Guys, I've solved the issue. The trick is that TS used real URI for redirect_uri param, but he shouldn't. Instead of this you have to use named URI parameter from ebay tokens page. Check docs at section: Getting the RuName value. This RuName should be used. Here is it: http://developer.ebay.com/Devzone/rest/ebay-rest/content/resources/images/ebay-rest/oauth-runame-a.bmp
· 2
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Which HTTP client are you using?
0 Likes 0 ·
First I've used Guzzle 5. Then, when I was succeed with RuName, I've switched to Oauth-Client from League: https://github.com/thephpleague/oauth2-client
0 Likes 0 ·
aerendir-ita avatar image
0 Likes"
aerendir-ita answered
@stalin-1945 sorry, but this doesn't work for me. Read my code on Stackoverflow: http://stackoverflow.com/questions/41091885/ebay-rest-api-invalid-request-when-exchanging-the-authorization-code-for-an-acc Can you post your code? I'm sure I'm doing wrong something really small and the error message is not so descriptive to make me able to understand where the error is. Your help would be very appreciated.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

surplusbydesign avatar image
0 Likes"
surplusbydesign answered
I am getting error: 401 Unauthorized. Please help.
10 |600 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.