ESPN API - How can I retrieve college basketball conferences using the Teams API?

StackOverflow https://stackoverflow.com/questions/19669867

  •  01-07-2022
  •  | 
  •  

Question

The support forums on ESPN.com recommend using Stack Overflow with the ESPN tag. That's why I'm here.

I'm trying to obtain a list of all NCAA college basketball teams using ESPN's Teams API. I started with this GET request:

http://api.espn.com/v1/sports/basketball/mens-college-basketball/teams?apikey=MY_API_KEY

That gave me a list of teams, but many of them are missing. For example, there is no Nebraska. So then I thought that maybe I need to get a list of teams by conference. So I read this in the documentation:

GROUPS: Allows for filtering by "group" or division, e.g. AL East, NFC South, etc. For group IDs and their corresponding values, make a request to http://developer.espn.com/v1/{resource}/leagues. Not applicable to golf and tennis.

So then I try to make a request to `http://developer.espn.com/v1/sports/basketball/mens-college-basketball/leagues?apikey=MY_API_KEY' and it says the page does not exist.

Is this a bug or user error?

Était-ce utile?

La solution

First, I think you forgot sports in the resource. Try this:

http://api.espn.com/v1/sports/basketball/mens-college-basketball?apikey=MY_API_KEY&leagues

That will return a mapping of integers to conferences it seems according to the documentation.

That fetched me:

{"name" :"Atlantic Coast Conference","abbreviation" :"acc","groupId" :2,"shortName" :"ACC"}

...and much more.

Then once you have that, let's say 2 = ACC. You should be able to do this:

http://api.espn.com/v1/sports/basketball/mens-college-basketball?groups=2&apikey=MY_API_KEY'

to get everything on ACC mens' basketball teams.

Bear in mind the API is in beta though.

Autres conseils

I could not figure out how to get a list of conferences, but I found out how to get the missing teams. When I was making the first get request, it was limiting me to 50 results by default:

http://api.espn.com/v1/sports/basketball/mens-college-basketball/teams?apikey=MY_API_KEY

They have a sandbox where you can play with your parameters, and I saw a limit and offset option:

http://developer.espn.com/io-docs

To get more than 50 results, you have to make multiple requests using the limit and offset parameters.

First Call: http://api.espn.com/v1/sports/basketball/mens-college-basketball/teams/?limit=50&offset=0&_accept=text%2Fxml&apikey=MY_API_KEY

Next Call: http://api.espn.com/v1/sports/basketball/mens-college-basketball/teams/?limit=50&offset=50&_accept=text%2Fxml&apikey=MY_API_KEY

And so on...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top