Pythe1337N / garmin-connect

Makes it simple to interface with Garmin Connect to get or set any data point.
MIT License
144 stars 58 forks source link

301 response #7

Open Emiliano-Bucci opened 3 years ago

Emiliano-Bucci commented 3 years ago

Hi! I've recently started to use this great library without any issues, but for some reason after a while i've start to get 301 when trying to access the user info GCClient.getUserInfo(). Do you know if this is a normal behavior? Maybe Garmin blocking me? Thanks a lot! :)

Edit: i see now a Too many request. Is there a limit, so, in the request we can made? Do you know of any limits?

Pythe1337N commented 3 years ago

Strange to get a 301 if there are too many requests. But Garmin's web services can be a bit strange sometimes. I've not experienced this myself since I only use it to plan daily workouts once every 24h, but it would make sense from Garmin's perspective to throttle the number of request that you can make.

Keep me posted if you find the limit on the number of requests and we can add it as reminder in the read me. It's probably set moderately high, which makes this a non-issue for most users.

cketcham commented 3 years ago

I had a similar issue. I had a script that was calling getActivities() that I ran ~10 times while I started to debug. Eventually it stopped working. I noticed it was redirecting to the sign in screen and I was able to go to that url in my browser and sign in and see the data. I found that changing the login post from urls.LOGIN_URL to urls.SIGNIN_URL fixed it (for now).

Pythe1337N commented 3 years ago

Ah, it most definitely sounds like an overload protection from Garmin's side. Would be nice to capture it and redo the sign in process. I haven't experienced this personally, neither on the web nor with this library. But i think there should be three possibilities.

The axios wrapper called client have automatic redirects disabled (handled manually) for some parts of the sign in process. This is probably why we get stuck on the 301, since it should redirect. If you're feeling adventurous, add some logging in the client for both requests and responses and I'm willing to help figure out what's going on.

@cketcham do you have an estimation to how many requests you did before getting kicked out? Dit your script request getActivities() over and over, or dit it run every 10 minutes?

cketcham commented 3 years ago

All I had was a script like this:

const { GarminConnect } = require('garmin-connect');
// Create a new Garmin Connect Client
const GCClient = new GarminConnect();
// Uses credentials from garmin.config.json or uses supplied params
await GCClient.login('my.email@example.com', 'MySecretPassword');
const activities = await GCClient.getActivities();

While I was testing I ran this maybe once a minute or more for about 10 minutes. And eventually it stopped working. That’s when I switched the url. I actually ran into it again and switched the url back and it started working again.

It does seem like rate limiting because I’m not having problems now when I just run the script a few times now that I have things working.