【问题标题】:Yahoo! Fantasy API Maximum Count?雅虎! Fantasy API 最大计数?
【发布时间】:2016-10-27 02:42:04
【问题描述】:

我正在尝试使用 Yahoo! 返回的 JSON 获取所有可用的球员。 Fantasy API,使用此资源:

http://fantasysports.yahooapis.com/fantasy/v2/game/nfl/players;status=A;position=RB

使用此 API 似乎总是最多返回 25 个玩家。我也尝试过使用;count=n 过滤器,但如果 n 高于 25,我仍然只能返回 25 名玩家。有人知道为什么是这样吗?以及如何获得更多?

这是我的代码:

from yahoo_oauth import OAuth1

oauth = OAuth1(None, None, from_file='oauth.json', base_url='http://fantasysports.yahooapis.com/fantasy/v2/')

uri = 'league/nfl.l.91364/players;position=RB;status=A;count=100'

if not oauth.token_is_valid():
    oauth.refresh_access_token

response = oauth.session.get(uri, params={'format': 'json'})

【问题讨论】:

  • 我其实也想知道同样的事情,你有想过吗?

标签: python json oauth yahoo-api


【解决方案1】:

我确实解决了这个问题。我发现最大“count”是25,但是“start”参数是这个操作的关键。似乎 API 为每个玩家附加了一个索引(无论如何排序),“start”参数是开始的索引。这可能看起来很奇怪,但我能找到的唯一方法是让所有玩家以 25 人为一组。所以我的代码解决方案如下所示:

from yahoo_oauth import OAuth1

oauth = OAuth1(None, None, from_file='oauth.json', base_url='http://fantasysports.yahooapis.com/fantasy/v2/')

done = False
start = 1
while(not done) :
    uri = 'league/nfl.l.<league>/players;position=RB;status=A;start=%s,count=25' % start

    if not oauth.token_is_valid():
        oauth.refresh_access_token

    response = oauth.session.get(uri, params={'format': 'json'})

    # parse response, get num of players, do stuff

    start += 25

    if numPlayersInResp < 25:
        done = True

【讨论】:

    猜你喜欢
    • 2011-11-21
    • 2012-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多