Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- //custom
- using Newtonsoft.Json; //used for json
- using System.Threading.Tasks; //used for async
- using System.Net.Http; //used to make http requests
- using System.Diagnostics; //used for Debug.WriteLine("xamarin::: " + "string");
- using Newtonsoft.Json.Linq; //used to directly access JObject
- using tinyapp.Model; //used to access nearby classes, such as Series.
- using System.Net.Http.Headers; //used for AuthenticationHeaderValue which is required for bearer token authorization
- namespace tinyapp.Model
- {
- class TVDBManager
- {
- const string apikey = "_";
- const string userkey = "_";
- const string username = "_";
- const string url = "https://api.thetvdb.com";
- const string sContentType = "application/json";
- //test
- const string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NjYzMjkwMTAsImlkIjoiZGV2aWNlcHJvZ3JhbW1pbmcyIiwib3JpZ19pYXQiOjE1NjYyNDI2MTAsInVzZXJpZCI6NDE0MTI4LCJ1c2VybmFtZSI6IkVsZmVuU2t5In0.NXWrThBo85vHctscCR_Ze40gJPbH3hx6yuBlEiES3KredFXWigs9IYmeXrkvCD2uJDfgeEvN0YdOyqAHSX2yluobMUnv_SOENPtAasQjpkJOq_JKKNpEVSMxHGFbHYkB9NvTgtLYX-itII3nBSURMs0gPC-DtK8w4J_w2oDD2MWJMHqsQKjSP50Zedj7O57ppx-doOzmW657JvPyLIjighAiEDcigP829UwHhxr4691KZdaQg2vcTu_E-Ldz3KrV6EOW0otusKZwOvb5llvdNXt9taZE9_7gP0IkVTe5VkWnkCDNaQctskAPxPQRKeiCG5qarqXQKFAJPqHHGmHnQw";
- public static async Task<List<Serie>> GetSearchResultsV2()
- {
- string url = "https://api.thetvdb.com/search/series?name=stranger";
- try
- {
- HttpClient client = new HttpClient();
- client.DefaultRequestHeaders.Add("Accept", "application/json");
- client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
- string json = await client.GetStringAsync(url);
- Debug.WriteLine("xamarin::: " + json);
- if (json != null)
- {
- List<Serie> listSeries = JsonConvert.DeserializeObject<List<Serie>>(json);
- return listSeries;
- }
- else
- {
- Debug.WriteLine("xamarin::: " + "GetSearchResultsV2::: " + "json did not load");
- Debug.WriteLine("xamarin::: " + json);
- return null;
- }
- }
- catch (Exception ex)
- {
- Debug.WriteLine("xamarin::: " + "error: " + ex.Message);
- throw ex;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement