Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetTrendingMoviesAsync() calling a non-working URL #424

Open
jason2li opened this issue Dec 12, 2022 · 9 comments
Open

GetTrendingMoviesAsync() calling a non-working URL #424

jason2li opened this issue Dec 12, 2022 · 9 comments

Comments

@jason2li
Copy link

When I simply call the following method:
client.GetTrendingMoviesAsync(TMDbLib.Objects.Trending.TimeWindow.Day)

It makes a call to:
https://api.themoviedb.org/3/trending/movie/Day?api_key={MYAPIKEY}

It returns the following error:
{"success":false,"status_code":5,"status_message":"Invalid parameters: Your request parameters are incorrect."}

After playing around with it, it looks like the issue is with the capital "D" in the word "Day". If I make a call to the same URL, but with a lowercase "d", everything works correctly.
https://api.themoviedb.org/3/trending/movie/day?api_key={MYAPIKEY}

Is there anything I can do to force a lowercase "d"? Or does this need to be resolved via a bugfix?

@itsoli91
Copy link

same here!

@LordMike
Copy link
Collaborator

LordMike commented Jan 9, 2023

Is this on .NET core or Framework?

GetTrendingMoviesAsync(Day) works fine in .NET Core.

@jason2li
Copy link
Author

jason2li commented Jan 9, 2023

.NET6

@LordMike
Copy link
Collaborator

LordMike commented Jan 9, 2023

This is TestApplication built for net5.0, with SDK 7.x, run like:

            var p1 = await client.GetTrendingMoviesAsync(TimeWindow.Day);

            Console.WriteLine(p1.Page);
            foreach (var searchMovie in p1.Results)
                Console.WriteLine(searchMovie.Id + " " + searchMovie.Title);

Output:
image

@itsoli91
Copy link

itsoli91 commented Jan 9, 2023

TimeWindow.Day adds a "Day" to the end of calling url, I cloned the project and convert it to lowercase (day), now it's working fine. I'm using .NET 7

@itsoli91
Copy link

itsoli91 commented Jan 9, 2023

It is also a good practice to keep everything lowercase while they are in a URL.

@LordMike
Copy link
Collaborator

LordMike commented Jan 9, 2023

Sure - and it is. In this library, all enum values follow C#'s Camel Case standard, so it's Day. I have then annotated all enums with [EnumValue()] with the value to use in some cases, which for Day is day. This is used in the Client, whenever it calls .GetDescription() on the enum value.

I'm not sure why you're getting Day. I asked about the .NET version because maybe the custom attributes behavior is different for .NET Framework. Another alternative is a minimal .NET that does not have reflection capabilities. EnumValue is defined within TMDbLib, so that should rule out any mixing of library versions.

If EnumValue truly does not work, you would also not be able to:

  • Use any of the Account methods
  • Call the Discover* API's and apply a sorting
  • Call the GetMovie* methods, with any extraMethods set.

The code for GetDescription does end up with a .ToString(), so if it wasn't possible to find the custom attribute, you would see Day.

@itsoli91
Copy link

itsoli91 commented Jan 9, 2023

Thank you for explanation.
Is there any specific reason that you are not using [Description("")]
This is works for me!

using System.ComponentModel;

Console.WriteLine(TimeWindow.Day);
Console.WriteLine(GetEnumDescription(TimeWindow.Day));

static string GetEnumDescription(Enum value)
{
    // Get the Description attribute value for the enum value
    var fi = value.GetType().GetField(value.ToString());
    if (fi == null)
        return value.ToString();

    var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

    return attributes.Length > 0 ? attributes[0].Description : value.ToString();
}

public enum TimeWindow
{
    [Description("day")] Day,
    [Description("week")] Week
}

Output:

Day
day
(process 21480) exited with code 0.
Press any key to close this window . . .

@benjimola
Copy link

TMDbLib.Objects.Trending.Tim

thanks for fixing the bug...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants