Open jason2li opened 1 year ago
same here!
Is this on .NET core or Framework?
GetTrendingMoviesAsync(Day)
works fine in .NET Core.
.NET6
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:
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
It is also a good practice to keep everything lowercase while they are in a URL.
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:
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
.
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 . . .
TMDbLib.Objects.Trending.Tim
thanks for fixing the bug...
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?