Forum Settings
Forums

[Nov 2021] Public information can now be accessed without authentication

New
Reply Disabled for Non-Club Members
Pages (2) « 1 [2]
Dec 12, 2022 8:55 AM
四十二

Offline
Mar 2016
441
I'm far from an expert in Swift, but I think this is your problem:

IrresponsibleCap said:
struct AnimeList: Codable {
    var data: [Anime]
}

struct Anime: Codable {
    var id: Int?
    var title: String?
}

"data" is not an array of Anime entries, but an array of objects containing a single field named "node". The value of each "node" corresponds to your Anime structure.
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Dec 12, 2022 2:49 PM
Offline
Mar 2021
3
ZeroCrystal said:

"data" is not an array of Anime entries, but an array of objects containing a single field named "node". The value of each "node" corresponds to your Anime structure.


struct AnimeList: Codable {
    var data: [Node]?
}

struct Node: Codable {
    var node: Anime?
    
    struct Anime: Codable {
        var id: Int?
        var title: String?
        var main_picture: MainPicture?
        var rank: Int?
        var mean: Double?
        var alternative_titles: AlternateTitles?
    }
}


I changed it to this and it works now, thank you so much, I did not even notice this.
Feb 23, 2023 6:35 AM

Offline
Jun 2009
58
I'm creating sonarr-like (sickchill, medusa-like) application that uses indexers to obtain metadata. I have reviewed the API agreement 3.(c) 

Can I hardcode X-MAL-CLIENT-ID I got from API panel? All I need is Search and Get Anime Details by ID which is public info.
Just like streamlink does with twitch, client_id is hardcoded here
class TwitchAPI:
    CLIENT_ID = "kimne78kx3ncx6brgo4mv6wki5h1ko"

There's really no point in authorizing each user individually since there' no need to modify data on user behalf

Am I allowed to hardcode client-id? So there's no action needed by users for application to work properly.
wMw_Feb 23, 2023 6:44 AM
Feb 23, 2023 9:54 AM
四十二

Offline
Mar 2016
441
wMw_ said:
Am I allowed to hardcode client-id? So there's no action needed by users for application to work properly.

Yes, you can. The OAuth 2.0 RFC defines two client types:
• Confidential:
    Clients capable of maintaining the confidentiality of their
    credentials (e.g., client implemented on a secure server with
    restricted access to the client credentials), or capable of secure
    client authentication using other means.

• Public:
    Clients incapable of maintaining the confidentiality of their
    credentials (e.g., clients executing on the device used by the
    resource owner, such as an installed native application or a web
    browser-based application), and incapable of secure client
    authentication via any other means.

Your application falls into the second category. MAL provides public clients with only a Client ID as they're unable to properly store any kind of credentials.
The Client ID is considered public information.

To register your application as a public client, you must set your App Type to "other", "Android", or "iOS". The "web" type is the only one reserved for confidential clients.
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Feb 23, 2023 10:30 AM

Offline
Jun 2009
58
Thank you for confirmation! Arigatou
Mar 24, 2023 11:32 PM
Offline
Feb 2015
1
When trying to return lists of anime, I've found that some anime are 'ghosts'. What I mean is, if you run the request: https://api.myanimelist.net/v2/anime?q=Lycoris_Recoil

Trying to get the result:  https://myanimelist.net/anime/50709/Lycoris_Recoil

but for some reason, in the response list, that specific anime doesn't exist, however, it returns this:  https://myanimelist.net/anime/54440/Lycoris_Recoil_Shinsaku_Animation
but this is not what I need to return.

Since Lycoris Recoil is in my currently watching, and I want to return a response of all 14 of the shows in my currently watching, no matter what I do,  I only get 13 items back in the list. Has anyone else encountered this issue or have an idea for a fix?
BattlemuffinsMar 24, 2023 11:35 PM
Mar 25, 2023 7:19 AM
四十二

Offline
Mar 2016
441
@Battlemuffins, your problem is that the query is missing the nsfw=true parameter, briefly explained at the very top of the documentation.

The following query will return both entries:
GET https://api.myanimelist.net/v2/anime?q=Lycoris_Recoil&nsfw=true

...
"data": [
        {
            "node": {
                "id": 54440,
                "title": "Lycoris Recoil (Shinsaku Animation)",
                "main_picture": {...}
            }
        },
        {
            "node": {
                "id": 50709,
                "title": "Lycoris Recoil",
                "main_picture": {...}
            }
        },
...


If you replace the underscore with a white space, you'll get the main anime as the first result:
GET https://api.myanimelist.net/v2/anime?q=Lycoris%20Recoil&nsfw=true

...
"data": [
        {
            "node": {
                "id": 50709,
                "title": "Lycoris Recoil",
                "main_picture": {...}
            }
        },
        {
            "node": {
                "id": 54440,
                "title": "Lycoris Recoil (Shinsaku Animation)",
                "main_picture": {...}
            }
        },
...


The NSFW parameter is poorly implemented. Each anime has a nsfw field that can either be white (safe for work), gray (may not be safe for work), or black (not safe for work).

By default, all new entries are marked as gray, and a DB moderator has to manually set it to the appropriate value. Many SFW series are still marked as gray, hidden from search results.

I suggest you add the nsfw=true parameter to all your queries in the future.
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Sep 11, 2023 5:33 AM
Offline
Jan 2017
3
Hey, I need a bit of help (I know kinda old thread sorry)... I am trying to fetch the data in a React app but I get an error, could anyone show me an example on how to create the fetch in a React UseEffect?
Sep 11, 2023 7:56 AM
四十二

Offline
Mar 2016
441
@BorisForis: Hi! I guess that you're trying to call the API straight from your web page. Unfortunately, you cannot do that since the API doesn't return the CORS headers required to call it directly from your browser.

There's no easy solution and it should be fixed by MAL. The usual workaround is to have some kind of middleware that can fix this for you. For example, a local application, a serverless function, a web proxy, or a remote server.
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Sep 11, 2023 8:43 AM
Offline
Jan 2017
3
Reply to ZeroCrystal
@BorisForis: Hi! I guess that you're trying to call the API straight from your web page. Unfortunately, you cannot do that since the API doesn't return the CORS headers required to call it directly from your browser.

There's no easy solution and it should be fixed by MAL. The usual workaround is to have some kind of middleware that can fix this for you. For example, a local application, a serverless function, a web proxy, or a remote server.
@ZeroCrystal I was hoping for a solution but in the end I ended up using jikan... Btw you don't happen to know what the highest mal_id is do you? So far I've gone as high as 54501
Sep 11, 2023 10:05 AM
四十二

Offline
Mar 2016
441
Reply to BorisForis
@ZeroCrystal I was hoping for a solution but in the end I ended up using jikan... Btw you don't happen to know what the highest mal_id is do you? So far I've gone as high as 54501
BorisForis said:
Btw you don't happen to know what the highest mal_id is do you? So far I've gone as high as 54501

New entries are added every day. Currently, 56626 is the latest ID.
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Sep 12, 2023 1:31 AM
Offline
Jan 2017
3
Thank you so much
Sep 20, 2023 7:26 AM
Offline
May 2022
1
It's working but I don't understand how to get Auth2.0 work. Specially code_challanged parameter
Sep 21, 2023 1:20 PM
四十二

Offline
Mar 2016
441
Reply to SuperDenZ
It's working but I don't understand how to get Auth2.0 work. Specially code_challanged parameter
@SuperDenZ Hi! The Code Challenge must be equal to your Client Verifier. You can take a look at my guide if you need help.
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Jan 30, 8:54 AM
Offline
Oct 2023
3
How can we apply this on android while using retrofit?
Jan 30, 3:03 PM
四十二

Offline
Mar 2016
441
Reply to oolyvi
How can we apply this on android while using retrofit?
@oolyvi Hi! I never used Retrofit before but, reading the documentation, it should be quite easy to accomplish.

Go here and scroll down till you reach the Header Manipulation section.
You should do something very close to that example: add the X-MAL-CLIENT-ID header, as explained in the first post, and it should work.
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Jan 30, 9:04 PM
Offline
Oct 2023
3
Reply to ZeroCrystal
@oolyvi Hi! I never used Retrofit before but, reading the documentation, it should be quite easy to accomplish.

Go here and scroll down till you reach the Header Manipulation section.
You should do something very close to that example: add the X-MAL-CLIENT-ID header, as explained in the first post, and it should work.
@ZeroCrystal I wrote something like this, but doesn't work

@Headers("X-MAL-CLIENT-ID: $CLIENT_ID")
    @GET("/v2/anime/season/{year}/{season}")
    suspend fun getSeasonalAnimes(
        @Query("year") year: Int,
        @Query("season") season: String,
    ): Response<SeasonalAnimes>
Jan 31, 5:56 AM
四十二

Offline
Mar 2016
441
Reply to oolyvi
@ZeroCrystal I wrote something like this, but doesn't work

@Headers("X-MAL-CLIENT-ID: $CLIENT_ID")
    @GET("/v2/anime/season/{year}/{season}")
    suspend fun getSeasonalAnimes(
        @Query("year") year: Int,
        @Query("season") season: String,
    ): Response<SeasonalAnimes>
@oolyvi What kind of error did you get?
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Jan 31, 7:19 AM
Offline
Oct 2023
3
Reply to ZeroCrystal
@oolyvi What kind of error did you get?
@ZeroCrystal I wrote this and now it works:
@GET("/v2/anime/season/{year}/{season}")
    suspend fun getSeasonalAnimes(
        @Header("X-MAL-CLIENT-ID") clientId: String,
        @Path("year") year: Int,
        @Path("season") season: String,
        @Query("limit") limit: Int
    ): Response<SeasonalAnimes>
Jan 31, 7:40 AM
四十二

Offline
Mar 2016
441
Great.
HTCPCP/1.0  ★ MetaMAL  ★ Picture credits: Living & 1041uuu
Reply Disabled for Non-Club Members
Pages (2) « 1 [2]

More topics from this board

» Unannounced API maintenance ? ( 1 2 )

Jhiday - Jan 31

73 by AxtoMax »»
Apr 26, 9:46 PM

» Which endpoints support nsfw query param?

crimson-megumin - Apr 21

2 by crimson-megumin »»
Apr 23, 2:29 PM

» Cant build the URL

tamcio_ - Dec 4, 2022

4 by Jotzy »»
Apr 22, 4:35 AM

» I made a new anime recommendation system for MyAnimeList

Asudox - Mar 21

4 by Asudox »»
Apr 11, 2:58 PM

» API Rate Limit?

Asudox - Jan 23

7 by pepeefirat »»
Mar 23, 3:57 AM
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login