The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

ESPN: Private Leagues

Tan Ho

2023-02-11

This vignette details how to connect to ESPN private leagues by retreiving the ESPN_S2 and SWID parameters from a live login. This cannot be done programmatically at this time.

Instructions

  1. Visit your main league page (i.e. https://fantasy.espn.com/football/team?leagueId=899513&seasonId=2020)
  2. Make sure you are logged in.
  3. Open Developer Tools (on Chrome/Firefox, right-click anywhere on the page and select Inspect Element)
  4. Go to Storage (for Firefox) or Application (for Chrome) and browse the Cookies available for fantasy.espn.com
  5. The values for SWID and ESPN_S2 are the parameters that are used by ffscrapr to connect to your private league. You can right-click and copy the values from here.

The most convenient way to handle these in any project is to store them as environment variables. You can run usethis::edit_r_environ() to add these to your user environment, by adding lines that look like:

TAN_ESPN_S2="AECt%2F12312Dwd5ktQSzfuG"
TAN_SWID="{1E6CC139-}"

The above values are both truncated (for security purposes) but ESPN_S2 is often over 250 characters long and SWID is about 38 characters long including the curly brackets.

After adding the above lines to your .Renviron and restarting R, you can access them in an espn_connect call by using Sys.getenv as per below:

conn <- espn_connect(
  season = 2019,
  league_id = 899513,
  espn_s2 = Sys.getenv("TAN_ESPN_S2"),
  swid = Sys.getenv("TAN_SWID")
)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.