jellyfin / TMDbLib

C#.Net library for TheMovieDB
MIT License
344 stars 128 forks source link

Authentication #395

Closed Podsyha closed 2 years ago

Podsyha commented 2 years ago

Hi. Sorry for my bad english.

Trying to get personalized movie lists. Directly via request: https://api.themoviedb.org/3/account/11103132/favorite/movies?api_key={key}&session_id={ses_id}&language=ru&sort_by=created_at.asc&page=1 everything works. A new session appears in the site settings through a direct request and through this library. But through this library I cannot get any of the following (movie lists, API configuration, account details).

Maybe I was wrong somewhere?

private TMDbClient m_Client = new(APIKEY) { DefaultImageLanguage = "ru", DefaultCountry = "ru", DefaultLanguage = "ru" };

    async public void Test()
    {
        Task<Token> _Token = m_Client.AuthenticationRequestAutenticationTokenAsync();
        await m_Client.AuthenticationValidateUserTokenAsync(_Token.Result.RequestToken, "Log", "Pass");
        Task<UserSession> _Session = m_Client.AuthenticationGetUserSessionAsync(_Token.Result.RequestToken);
        await m_Client.SetSessionInformationAsync(_Session.Result.SessionId, SessionType.UserSession);

        Task<APIConfiguration> _ConfigAPI = m_Client.GetAPIConfiguration();

        Task<SearchContainer<SearchMovie>> _WatchList 
            = m_Client.AccountGetMovieWatchlistAsync(1, AccountSortBy.CreatedAt, SortOrder.Ascending, "ru");

        Task<SearchContainer<SearchMovieWithRating>> _RatedList = 
            m_Client.AccountGetRatedMoviesAsync(1, AccountSortBy.CreatedAt, SortOrder.Ascending, "ru");

        Task<SearchContainer<SearchMovie>> _FavoritList = m_Client.AccountGetFavoriteMoviesAsync();

        AccountDetails _AccDetails = m_Client.ActiveAccount;
    }
Podsyha commented 2 years ago

If I am through the HttpClient after the block:

Task<Token> _Token = m_Client.AuthenticationRequestAutenticationTokenAsync();
        await m_Client.AuthenticationValidateUserTokenAsync(_Token.Result.RequestToken, "Log", "Pass");
        Task<UserSession> _Session = m_Client.AuthenticationGetUserSessionAsync(_Token.Result.RequestToken);
        await m_Client.SetSessionInformationAsync(_Session.Result.SessionId, SessionType.UserSession);

I make an independent request:

string Api = $"https://api.themoviedb.org/3/account/11103132/favorite/movies?";
            string Url = $"api_key={APIKEY}&session_id={_Session.Result.SessionId}&language=ru&sort_by=created_at.asc&page=1";
            string Uri = Api + Url;

            HttpClient Client = new HttpClient();
            HttpResponseMessage Response = await Client.GetAsync(Uri);
            Response.EnsureSuccessStatusCode();
            string ResponseBody = await Response.Content.ReadAsStringAsync();

Then I will answer satisfactory. As if the problem is in the AccountGetMovieWatchlistAsync method, etc.

Podsyha commented 2 years ago

I made a very stupid mistake by starting to work without understanding asynchrony.

async public void Test()
        {
            Task<Token> _Token = m_Client.AuthenticationRequestAutenticationTokenAsync();
            await m_Client.AuthenticationValidateUserTokenAsync(_Token.Result.RequestToken, "Log", "Pass");
            Task<UserSession> _Session = m_Client.AuthenticationGetUserSessionAsync(_Token.Result.RequestToken);
            await m_Client.SetSessionInformationAsync(_Session.Result.SessionId, SessionType.UserSession);

            Task<APIConfiguration> _ConfigAPI = m_Client.GetAPIConfiguration();

            SearchContainer<SearchMovie> _WatchList
                = await m_Client.AccountGetMovieWatchlistAsync(1, AccountSortBy.CreatedAt, SortOrder.Ascending, "ru");

            SearchContainer<SearchMovieWithRating> _RatedList =
                await m_Client.AccountGetRatedMoviesAsync(1, AccountSortBy.CreatedAt, SortOrder.Ascending, "ru");

            SearchContainer<SearchMovie> _FavoritList = await m_Client.AccountGetFavoriteMoviesAsync();

            AccountDetails _AccDetails = m_Client.ActiveAccount;
        }