Skip to content

OpenXbox/xbox-webapi-csharp

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

Xbox WebAPI library for .NET

GitHub Workflow - Build NuGet Discord

C# Xbox WebAPI, includes support for authentication with Windows Live / Xbox Live.

Usage

Basic authentication flow

using System;
using XboxWebApi.Authentication;
using XboxWebApi.Authentication.Model;

// ...

string requestUrl = AuthenticationService.GetWindowsLiveAuthenticationUrl();

/* Call requestUrl via WebWidget or manually and authenticate */

WindowsLiveResponse response = AuthenticationService.ParseWindowsLiveResponse(
    "<Received Redirection URL>");

AuthenticationService authenticator = new AuthenticationService(response);

string tokenFilePath = "tokens.json";
bool success = await authenticator.AuthenticateAsync();
if (!success)
    throw new Exception("Authentication failed!");

success = await authenticator.DumpToJsonFileAsync(tokenFilePath);
if (!success)
    throw new Exception("Failed to dump tokens");

Console.WriteLine("Tokens saved to {}", tokenFilePath);

Console.WriteLine(authenticator.XToken);
Console.WriteLine(authenticator.UserInformation);

Save token to JSON

using XboxWebApi.Authentication;

await authenticator.DumpToJsonFileAsync(tokenFilePath);

Load token from JSON

using XboxWebApi.Authentication;

AuthenticationService authenticator = await AuthenticationService.LoadFromJsonFileAsync("tokens.json");

Example Api Usage

using System;
using XboxWebApi.Common;
using XboxWebApi.Services;
using XboxWebApi.Services.Api;
using XboxWebApi.Services.Model;
using XboxWebApi.Authentication;

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

XblConfiguration xblConfig = new XblConfiguration(authenticator.XToken, XblLanguage.United_States);

PresenceService presenceService = new PresenceService(xblConfig);
PeopleService peopleService = new PeopleService(xblConfig);
MessageService messageService = new MessageService(xblConfig);
// ... more services

var friends = await peopleService.GetFriendsAsync();
var presenceBatch = await presenceService.GetPresenceBatchAsync(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.

Credits

Informations on endpoints gathered from:

Disclaimer

Xbox, Xbox One, Smartglass and Xbox Live are trademarks of Microsoft Corporation. Team OpenXbox is in no way endorsed by or affiliated with Microsoft Corporation, or any associated subsidiaries, logos or trademarks.

About

C# Xbox WebAPI, includes support for authentication with Windows Live / Xbox Live

Resources

License

Stars

Watchers

Forks

Packages

No packages published