initial commit
This commit is contained in:
25
LetterBoxdUnwatchedGenerator/LetterBoxdConnection.cs
Normal file
25
LetterBoxdUnwatchedGenerator/LetterBoxdConnection.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
namespace LetterBoxdUnwatchedGenerator
|
||||
{
|
||||
public class LetterBoxdConnection
|
||||
{
|
||||
const string baseUrl = "https://letterboxd.com/api/v0/";
|
||||
HttpClient httpClient;
|
||||
|
||||
public LetterBoxdConnection()
|
||||
{
|
||||
//Authentication
|
||||
httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
//add url form encoded content
|
||||
var results = httpClient.PostAsync(baseUrl + "auth/token", new StringContent("grant_type=password&username=USERNAME&password=PASSWORD", MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded"))); //, Encoding.UTF8, "application/x-www-form-urlencoded"));
|
||||
|
||||
results.Result.EnsureSuccessStatusCode();
|
||||
var bearer = results.Result.Content.ReadAsStringAsync().Result;
|
||||
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearer);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user