To call a method in the RestrictedService, you need a token
for the specific user that you want to call methods for.
Please read the tutorial on how to obtain a token before continuing.
Code example
01: [STAThread]
02: static void Main(string[] args) {
03:
04: try {
05: string appId = "yourAppId"; // Use your application Id
06: string appServiceKey = "yourAppServiceKey"; // Use your application service key
07: int userId = 0; // The user Id of the user that you want to impersonate
08: string token = "yourToken"; // The Token for the specific user and application
09:
10: Tradera.Api.RestrictedService restrictedService = new Tradera.Api.RestrictedService();
11: restrictedService.Url += string.Format("?appId={0}&appKey={1}", appId, appServiceKey);
12: restrictedService.Url += string.Format("&userId={0}&token={1}", userId, token);
13: Tradera.Api.Item[] items =
14: restrictedService.GetSellerItems(0, 0, DateTime.MinValue, DateTime.MaxValue);
15:
16: if(items != null && items.Length != 0) {
17: foreach(api.tradera.com1.Item item in items) {
18: Console.WriteLine(
19: "Item #{0} {1}", item.Id, item.ShortDescription);
20: }
21:
22: } else {
23: Console.WriteLine("Request for items returned null");
24: }
25:
26: Console.ReadLine();
27:
28: } catch(Exception exception) {
29:
30: Console.WriteLine("Error: {0}", exception.Message);
31: Console.WriteLine(exception.StackTrace);
32: Console.ReadLine();
33: }
34: }
Remarks
- Add your application Id and application service key on lines 5 and 6.
- Supply the Id and token for the current user on line 7 and 8.
- Use the name you gave your web reference in place of the Tradera.Api prefix used in lines 10 and 13.