Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed Jun 7, 2018
1 parent e19003b commit 6573e02
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,63 @@ Console.WriteLine(authenticator.XToken);
Console.WriteLine(authenticator.UserInformation);
```

Save token to JSON

```cs
using System.IO;
using XboxWebApi.Common;

string xtoken_json = NewtonsoftJsonSerializer.Default.Serialize(authenticator.XToken);
string refresh_json = NewtonsoftJsonSerializer.Default.Serialize(authenticator.RefreshToken);
File.WriteAllText("xtoken.json", json);
File.WriteAllText("refresh_token.json", json);
```

Load token from JSON

```cs
using System.IO;
using XboxWebApi.Common;
using XboxWebApi.Authentication;

string xtoken_json = File.ReadAllText("xtoken.json");
string refresh_json = File.ReadAllText("refresh_token.json");
XToken xtoken = NewtonsoftJsonSerializer.Default.Deserialize<XToken>(xtoken_json);
RefreshToken refresh_token = NewtonsoftJsonSerializer.Default.Deserialize<RefreshToken>(refresh_json);
```

Example Api Usage

```cs
using System;
using XboxWebApi.Common;
using XboxWebApi.Extensions;
using XboxWebApi.Services;
using XboxWebApi.Services.Api;
using XboxWebApi.Services.Model;

if (!xtoken.Valid)
{
Console.WriteLine("Token expired, please refresh / reauthenticate");
return;
}

XblConfiguration xblConfig = new XblConfiguration(xtoken.UserInformation,
xtoken, XblLanguage.United_States);

PresenceService presenceService = new PresenceService(xblConfig);
PeopleService peopleService = new PeopleService(xblConfig);
MessageService messageService = new MessageService(xblConfig);
// ... more services
var friends = peopleService.GetFriends();
var presenceBatch = presenceService.GetPresenceBatch(friends.GetXuids());
for (int i=0; i < friends.TotalCount; i++)
{
Console.WriteLine($"{presenceBatch[i].Xuid} is {presenceBatch[i].State}");
}
```

## Documentation

Not yet, please look at `XboxWebApi.Tests` for now.
Expand Down

0 comments on commit 6573e02

Please sign in to comment.