TMDbLib icon indicating copy to clipboard operation
TMDbLib copied to clipboard

GetTrendingMoviesAsync() calling a non-working URL

Open jason2li opened this issue 2 years ago • 9 comments

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?

jason2li avatar Dec 12 '22 16:12 jason2li

same here!

itsoli91 avatar Dec 14 '22 20:12 itsoli91

Is this on .NET core or Framework?

GetTrendingMoviesAsync(Day) works fine in .NET Core.

LordMike avatar Jan 09 '23 21:01 LordMike

.NET6

jason2li avatar Jan 09 '23 21:01 jason2li

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

LordMike avatar Jan 09 '23 21:01 LordMike

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 avatar Jan 09 '23 22:01 itsoli91

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

itsoli91 avatar Jan 09 '23 22:01 itsoli91

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.

LordMike avatar Jan 09 '23 22:01 LordMike

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 . . .

itsoli91 avatar Jan 09 '23 23:01 itsoli91

TMDbLib.Objects.Trending.Tim

thanks for fixing the bug...

benjimola avatar Jan 17 '23 16:01 benjimola