question

zwat93 avatar image
0 Likes"
zwat93 asked

Simple Authentication help C#,How to make a simple search call C# Authentication issue

Hello,

I am extremely new to API calls so I apologize if I am missing obvious information.

I wish to use the eBay search api to search for item data. So I looked at the documentation and though I knew how to make the call. I keep getting a 401 error. Here is my code. I am unclear on all of the steps to actually authenticate. I have a production key. There are also Oauth tokens. What do I need here?


var myUri = new Uri("https://api.ebay.com/buy/browse/v1/item_summary/search?q=drone&limit=3");

var myWebRequest = WebRequest.Create(myUri);

var myHttpWebRequest = (HttpWebRequest)myWebRequest;

myHttpWebRequest.PreAuthenticate = true;

myHttpWebRequest.Headers.Add("Authorization", "Bearer " + "<My Client ID goes here>");

myHttpWebRequest.Accept = "application/json";


var myWebResponse = myWebRequest.GetResponse();

var responseStream = myWebResponse.GetResponseStream();

if (responseStream == null) return null;


var myStreamReader = new StreamReader(responseStream, Encoding.Default);

var json = myStreamReader.ReadToEnd();


responseStream.Close();

myWebResponse.Close();


return json;

,

I am very new to the api and only wish to use it to search for item data. I have production keys that i am trying to use to authenticate with. I keep getting 401 error.


Here is my code. I was trying to follow the documentation details but there are no clear examples. I apologize if it seems like I have no idea what i am doing. This is my first interaction making api calls. This is all for a school project.


var myUri = new Uri("https://api.ebay.com/buy/browse/v1/item_summary/search?q=drone&limit=3");

var myWebRequest = WebRequest.Create(myUri);

var myHttpWebRequest = (HttpWebRequest)myWebRequest;

myHttpWebRequest.PreAuthenticate = true;

myHttpWebRequest.Headers.Add("Authorization", "Bearer " + "<My ClientId Goes Here>");

myHttpWebRequest.Accept = "application/json";


var myWebResponse = myWebRequest.GetResponse();

var responseStream = myWebResponse.GetResponseStream();

if (responseStream == null) return null;


var myStreamReader = new StreamReader(responseStream, Encoding.Default);

var json = myStreamReader.ReadToEnd();


responseStream.Close();

myWebResponse.Close();


return json;

searchauthentication failedauthentication
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.

0 Answers

· Write an Answer

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.