【发布时间】:2018-04-07 17:23:10
【问题描述】:
我在使用 Yahoo Fantasy API 时遇到问题。使用示例here 和here,我开发了一个非常hacky 的解决方案来获取我的连接集。
首先,我使用以下代码创建一个 oauth1 令牌:
library(httr)
cKey <- "mykey"
cSecret <- "mysecret"
oauth_endpoints("yahoo")
myapp <- oauth_app("yahoo", key = cKey, secret = cSecret)
token <- oauth1.0_token(oauth_endpoints("yahoo"), myapp)
然后我有另一段代码让我签名:
yahoo <-oauth_endpoints("yahoo")
myapp <- oauth_app("yahoo", key=cKey, secret=cSecret)
yahoo_token<- oauth2.0_token(yahoo, myapp, cache=T, use_oob = T)
sig <- sign_oauth1.0(myapp, yahoo_token$oauth_token, yahoo_token$oauth_token_secret)
在我看来,我应该只需要其中一个来访问 API,但我不能只使用其中一个。
无论如何,这确实可以让我建立连接。为了访问 API,我需要游戏 ID。根据上面链接的演练之一中的说明,我使用此代码来执行此操作:
page_mlb <-GET("http://fantasysports.yahooapis.com/fantasy/v2/game/mlb?format=json", sig)
page_mlb_parse <- content(page_mlb, as="parsed", encoding="utf-8")
game_key <- page_mlb_parse[["fantasy_content"]][["game"]][[1]][["game_key"]]
game_key 最终变成了378。因此,我应该能够使用我刚刚找到的游戏密钥以及我的联赛 ID 94107 访问我的联赛的联赛积分榜之类的东西,这是我的联赛独有的。
leagueKey <- paste0(game_key,'.l.',lg_id)
baseURL <- "http://fantasysports.yahooapis.com/fantasy/v2/league/"
standingsURL<-paste(baseURL, leagueKey, "/standings", sep="")
standings_page <- GET(standingsURL,sig)
standings_parse <- content(standings_page, as = "parsed", encoding = "utf-8")
但是当我将它打印到屏幕上时,我得到:
> standings_parse
{xml_document}
<error lang="en-us" uri="http://fantasysports.yahooapis.com/fantasy/v2/league/378.l.94107/standings" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://www.yahooapis.com/v1/base.rng">
[1] <description>You are not allowed to view this page because you are not in this league.</description>
[2] <detail/>
回复:You are not allowed to view this page because you are not in this league 是我挂在这里的原因。我正在使用相同的 Yahoo 登录来创建我用来建立我的幻想团队的 API。
有什么建议吗?
【问题讨论】:
-
我也有同样的问题。你在这个问题上有什么进展吗?
-
@Phil,不,没有进展报告。