Created
April 3, 2016 07:21
-
-
Save ChrisBriggsy/056a5e5f5b4133f5b8f92fc8dd132149 to your computer and use it in GitHub Desktop.
Getting Started Developing UWP apps for Xbox One - Step 5. Adding the code behind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Windows.UI.Xaml.Controls; | |
namespace IoTBackUp | |
{ | |
public sealed partial class MainPage : Page | |
{ | |
public MainPage() | |
{ | |
this.InitializeComponent(); | |
Display(); | |
} | |
private async void Display() | |
{ | |
var data = await GetData(); | |
Temperature.Text = data.main.temp.ToString(); | |
Humdity.Text = data.main.humidity.ToString(); | |
} | |
public async Task<OpenWeatherMapData> GetData() | |
{ | |
var httpClient = new HttpClient(); | |
var APPID = "ReplaceWithYourVaildKey"; | |
//Since I first gave this talk OpenWeatherMap have changed their API policy | |
//Therefore if you want to run this sample, sign up for a free account and replace the APPID | |
// http://openweathermap.org/faq#error401 | |
var response = await httpClient.GetAsync("http://api.openweathermap.org/data/2.5/weather?q=Melbourne&units=metric&APPID=" + APPID); | |
return JsonConvert.DeserializeObject<OpenWeatherMapData>(await response.Content.ReadAsStringAsync()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment