dvcol / trakt-http-client

Fetch based http client for trakt.tv API
MIT License
2 stars 0 forks source link

Not work.. #1

Open michalss opened 2 days ago

michalss commented 2 days ago

Hi, Spend hours to make this work. It simply does not work..

its always return some giberish for this ID: 199331

{"limit":{"rate":{"name":"UNAUTHED_API_GET_LIMIT","period":300,"limit":1000,"remaining":999,"until":"2024-11-21T19:40:00Z"}}}

const traktApi = {
  ...minimalTraktApi,
  calendars,
  episodes,
};

const traktSettings = {
  client_id: process.env.TRAKT_CLIENT_ID,
  client_secret: process.env.TRAKT_CLIENT_SECRET,
  redirect_uri: 'https://localhost/callback',
  endpoint: Config.Endpoint.Production,
  useragent: 'MyApp/1.0.0',
};

const traktParser = async (id, mediatype) => {

  const { access_token, refresh_token } = await authenticate(_db);
  console.log('Tokens:', access_token, refresh_token, id);

const initAuthentication = {
  access_token: access_token,
  refresh_token: refresh_token,
  created_at: Math.floor(Date.now() / 1000),
  expires_in: 7775999, 
};

  let traktClient = new TraktClient(traktSettings, initAuthentication, traktApi);
 try {

   const result = await traktClient.episodes?.summary({
      id: id,
      season: 1,
      episode: 1,
    });
    console.log('Episode Summary:', result);
   return result;

  } catch (error) {
    console.error('Error fetching episode summary:', error);
    throw error;
  }
};

also im missing some real example how to use auth device method. It was so paintfull i had to write my own .. :(\

Code looks very solid but is it really that hard to write whole usage example with auth + 1 request for show for example ?

michalss commented 2 days ago

btw useing it in commonJS project..

dvcol commented 2 days ago

The API is limiting calls for unauth clients as per the response.

To call this specific endpoint you need a valid session.

You can find more information on trakt's official API doc here.

And if you want a more concrete example, you can have a look at this live implementation.

Note howerver, that this repo is mainly used as a client for trakt-extension, only the endpoint in used in the app have been thourougly tested.

{
    "limit":
    {
        "rate":
        {
            "name": "UNAUTHED_API_GET_LIMIT",
            "period": 300,
            "limit": 1000,
            "remaining": 999,
            "until": "2024-11-21T19:40:00Z"
        }
    }
}