public static async Task <string> GetUserId(string oauth_token, string oauth_verifier) { var request = new HttpRequestMessage(HttpMethod.Post, "https://api.twitter.com/oauth/access_token"); request.Content = new StringContent("oauth_verifier=" + oauth_verifier, Encoding.UTF8, "application/x-www-form-urlencoded"); var parameters = new SortedDictionary <string, string>(); parameters.Add("oauth_verifier", oauth_verifier); request.Headers.Add("Authorization", TwitterAuthenticator.GenerateAuthString("POST", "https://api.twitter.com/oauth/access_token", parameters, null, oauth_token)); var response = await client.SendAsync(request); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); throw new NotImplementedException(); } return((await response.Content.ReadAsStringAsync()) .Split('&') .Select(s => s.Split('=')) .Where(ss => ss[0] == "user_id") .Single()[1]); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected async override void OnNavigatedTo(NavigationEventArgs e) { client.BaseAddress = new Uri("https://api.twitter.com"); var request = new HttpRequestMessage(HttpMethod.Post, "/oauth/request_token"); request.Headers.Add("Authorization", TwitterAuthenticator.GenerateAuthString("POST", "https://api.twitter.com/oauth/request_token", new SortedDictionary <string, string>(), "http://quarr.us")); var response = await client.SendAsync(request); if (!response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); throw new NotImplementedException(); } var responseText = await response.Content.ReadAsStringAsync(); Web.Navigate(new Uri("https://api.twitter.com/oauth/authorize?" + responseText.Split('\0').First().Split('&').First())); Web.NavigationStarting += Web_NavigationStarting; }