master |
---|
A client library for the ebay API targeting .NET standard 2.0.
var client = new EbayClient("clientId", "clientSecret");
var item = await client.BrowseAPI.Item.GetItem("itemId");
var itemSearch = await client.BrowseAPI.ItemSummary.Search("drone", 10);
Currently, only the Browse API is supported. Ebay.net follows the same hierarchical structure as the official documentation.
For instance, to call 'Get Item', you would do: client.BrowseAPI.Item.GetItem(<itemId>);
- Browse API
- Item Summary
- Item
Add the package:
dotnet add package Ebay.Net
Ebay.net supports both Production and Sandbox environments. You set the Environment
enum during initialisation of the client or authenticator like shown in examples below. The default is Environment.Production
.
You will require your ClientID and your ClientSecret, which you can grab from here.
You authenticate via OAuth2 in any of the following ways:
// Simplest way is to pass your clientId and secret directly
var client = new EbayClient("clientId", "clientSecret", Environment.Production);
// Format specification: https://developer.ebay.com/api-docs/static/oauth-base64-credentials.html
// You can use https://www.base64encode.org and encode: yourClientId:yourClientSecret
var client = new EbayClient("base64encoded");
// Manually create and set the authenticator:
// You can also add your own implementation by implementing IOAuth2Authenticator
var auth = new OAuth2Authenticator("base64encoded");
var client = new EbayClient(auth);
Ebay.net will handle token expiration and renew for you.
Any error in the library will result in a generic EbayException
. You can extract the message to determine the cause of the issue.
try
{
var client = new EbayClient(...);
var item = await client.BrowseAPI.Item.GetItem("Fake-Item-Will-Throw-Exception");
}
catch(EbayException ex)
{
var message = ex.Message;
var stackTrace = e.InnerException;
}