Yahoo OAuth:Fantasy Sports API随机返回401错误

时间:2017-10-02 23:04:44

标签: php api oauth yahoo-oauth

多年来,我一直在使用带有OAuth 1和PHP的Yahoo Fantasy Sports API,没有任何问题。在过去的几周内,用户授权失败了。

基本上,在从雅虎获得一个有效的令牌之后,当我们从API获取信息时,我们得到401错误的响应。非常奇怪的是,我们随机获得401错误或数据作为回应。

我甚至尝试过Yahoo提供的示例PHP脚本 - 同样的错误。这是使用脚本的CLI调用的快照 - 两个快速连续的调用,第一个返回401,第二个返回数据:

root@dednew:/var/www/fhg# /opt/php-5.6/bin/php tester.php
Got access token information!
 Token: A=GMj2OgnmgiODpfvH9HkbcQr9Phz2qNYOhTLbEfdNMGz7NGJ6c9KDNkxndObLi8vD.USTPkaTvdPrnoIkZo7QYI277fOs1fJjuOCVapOm16qoZUcP7BFkgbC9ay1iLdF7__BHNiVMS75Jtr.p6249F02Z2Ld2dE8KkUNxDtwF8tSi5UBCL1R1xd0tzusw0cITPBJGd5_wMwf5E3BVEr1ZmoQbYgGBwMpcQvIPFbmw7PaByQPvhZ7OhriYVe1sFDk_paGki4ThaC.rua9QoUx25Txpgiksp3PqUfrq4Mnp3fqJvG4ZZbMD4VBRnQaSyibeJR5QiaB1sk088.YW7SdPRLXU_2I78A_jnYro8AMZD_DRAatU9Va6WL1gdBcVccO8WHu4DQwSFESfadl8qFrEEPA2hyfzlPDdp2BFoyFORjOvAqI_O5agLM_4jl1tJPXSHAYjeLHpBgazdP23Qcuj4doG_JYBTCQW_BKSuMKLUd15sLy3J4GcqiPiE7jQ7JGrKxjt417sRcjVL0ziksatzvzeFyXNyrYBE0YohFqYjd_4_hSUMX9SgnVcXEmhPxO6zlISpcj0OVpSqQyZ752SuZEazzBVtqSGFgz0IWd8.fV.g5EmXr.FLh.5fc8ShkHM5Zxk1HfowIZtzuAfco32_SLpe3047gq0lt.nu4kY_L57CnsPVopSsol6F.nNiPAM9jZLrDPZP1RprgaDlbKdOPukLw5SGzEHlOArXcfIFL37n4vVg53u9jK7Nv1krw1kzgwWE6meGVUdc7JRcdTtJf6FB2T7.NqFmYkL
 Secret: 32cbad8c8b5adbb441458615d5db7f30d3128749
 Session Handle: AMW.zllcRE9V.ztlfxWt0TkfIMCDVue0jurjx1FlIEux4l71mkRv

Error: Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)
Error Code: 401
Response: <?xml version="1.0" encoding="UTF-8"?>
<error xml:lang="en-us" yahoo:uri="http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=nfl/teams?oauth_consumer_key=dj0yJmk9cE0yWnZzRVFEbjhFJmQ9WVdrOWNuY3pOVWczTXpJbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1hYw--&amp;amp;oauth_signature_method=HMAC-SHA1&amp;amp;oauth_nonce=87474055259cedbfd522a68.21090926&amp;amp;oauth_timestamp=1506728957&amp;amp;oauth_version=1.0&amp;amp;oauth_token=A%3DGMj2OgnmgiODpfvH9HkbcQr9Phz2qNYOhTLbEfdNMGz7NGJ6c9KDNkxndObLi8vD.USTPkaTvdPrnoIkZo7QYI277fOs1fJjuOCVapOm16qoZUcP7BFkgbC9ay1iLdF7__BHNiVMS75Jtr.p6249F02Z2Ld2dE8KkUNxDtwF8tSi5UBCL1R1xd0tzusw0cITPBJGd5_wMwf5E3BVEr1ZmoQbYgGBwMpcQvIPFbmw7PaByQPvhZ7OhriYVe1sFDk_paGki4ThaC.rua9QoUx25Txpgiksp3PqUfrq4Mnp3fqJvG4ZZbMD4VBRnQaSyibeJR5QiaB1sk088.YW7SdPRLXU_2I78A_jnYro8AMZD_DRAatU9Va6WL1gdBcVccO8WHu4DQwSFESfadl8qFrEEPA2hyfzlPDdp2BFoyFORjOvAqI_O5agLM_4jl1tJPXSHAYjeLHpBgazdP23Qcuj4doG_JYBTCQW_BKSuMKLUd15sLy3J4GcqiPiE7jQ7JGrKxjt417sRcjVL0ziksatzvzeFyXNyrYBE0YohFqYjd_4_hSUMX9SgnVcXEmhPxO6zlISpcj0OVpSqQyZ752SuZEazzBVtqSGFgz0IWd8.fV.g5EmXr.FLh.5fc8ShkHM5Zxk1HfowIZtzuAfco32_SLpe3047gq0lt.nu4kY_L57CnsPVopSsol6F.nNiPAM9jZLrDPZP1RprgaDlbKdOPukLw5SGzEHlOArXcfIFL37n4vVg53u9jK7Nv1krw1kzgwWE6meGVUdc7JRcdTtJf6FB2T7.NqFmYkL&amp;amp;oauth_signature=3N%2Fv7E94sSz7u1T%2FnZw7LSL%2FqH8%3D" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://www.yahooapis.com/v1/base.rng">
 <description>Invalid cookie, please log in again.</description>
 <detail/>
</error>

Array
(
    [oauth_token] => A=UOj1pgHd.AMPSWtSpTpOV7H26tlA5pBx6JFxqZ5t1XDH.Tbat9FvZasADKWuXm9oKKr_vaaWZBRS2RyP4eAmeOEBWFM3HSg1VHrtr8Z9XDhfr_n6b5ujgyFt_Grw8pf5pbfC0x4YelJCH0HDOdmg3tatVsDBLdc79WkQnJ6.4NS2IXBskwpeVGxRpKiH3EYSJ1z_5L6hZQtsegK1jgqsyzezvf6BgJjeOUO84mI175VOX5KY4ht2WE.qzOK21vvxilWlKOT2lTvJdYNH.47B2y.XXqw6WNwfqoIrChVkcr4l_oqE_gzeHlsox6Z1gtl1WgDGeLWqS9iJZqn0AWvbgOk38FVTFkJcYprPthOQBtyLZyom04NVIStnuZ.xc7EEZVKHg88_lHj28uyrbF8ZPD4f3bI0A8nHX6f9Z3ZhgxbSLyG44BiTjAp..Q3qXB45I4gvHqlEferLBwG6T.NHV48XDk3cbf3y7SbtjEaDwr6ityMkp2xMUhqHMJQ4DfxmuRejwadZ0FeK8sqfkZSR2nnQiGN3t61Sla.tf3fFHusbHVEj2Mp2Mk85FL2APWWOtNA6QRSMou38FX5x2YnWYpTkcC9QXxFniWY.eU4lupyVT.KX4hvsc2xBxhbD9zfnGMef1Yg_7w4rlMUbrpAw9JAKtDAHFJS6VvY.FnRV3SiDd3Ck8dEx0BGLSmxE052qeRGjnxTv_0G4.Kj.4vFY4ztBDtlKZTLUvEbPZJKDU0CXSTfOEo1C99e3R19SS8Eh_KVToP3Z81_7QWrLzCSfJqXFQUdQLfgUzCJV
    [oauth_token_secret] => 6fd5d695882ef63b18bf786be3c8463cdea33e7f
    [oauth_expires_in] => 3600
    [oauth_session_handle] => AMW.zllcRE9V.ztlfxWt0TkfIMCDVue0jurjx1FlIEux4l71mkRv
    [oauth_authorization_expires_in] => 640754690
    [xoauth_yahoo_guid] => WI3IFMZVEK4K7CINH6WJSKPU7A
)
Was able to refresh access token:
 Token: A=UOj1pgHd.AMPSWtSpTpOV7H26tlA5pBx6JFxqZ5t1XDH.Tbat9FvZasADKWuXm9oKKr_vaaWZBRS2RyP4eAmeOEBWFM3HSg1VHrtr8Z9XDhfr_n6b5ujgyFt_Grw8pf5pbfC0x4YelJCH0HDOdmg3tatVsDBLdc79WkQnJ6.4NS2IXBskwpeVGxRpKiH3EYSJ1z_5L6hZQtsegK1jgqsyzezvf6BgJjeOUO84mI175VOX5KY4ht2WE.qzOK21vvxilWlKOT2lTvJdYNH.47B2y.XXqw6WNwfqoIrChVkcr4l_oqE_gzeHlsox6Z1gtl1WgDGeLWqS9iJZqn0AWvbgOk38FVTFkJcYprPthOQBtyLZyom04NVIStnuZ.xc7EEZVKHg88_lHj28uyrbF8ZPD4f3bI0A8nHX6f9Z3ZhgxbSLyG44BiTjAp..Q3qXB45I4gvHqlEferLBwG6T.NHV48XDk3cbf3y7SbtjEaDwr6ityMkp2xMUhqHMJQ4DfxmuRejwadZ0FeK8sqfkZSR2nnQiGN3t61Sla.tf3fFHusbHVEj2Mp2Mk85FL2APWWOtNA6QRSMou38FX5x2YnWYpTkcC9QXxFniWY.eU4lupyVT.KX4hvsc2xBxhbD9zfnGMef1Yg_7w4rlMUbrpAw9JAKtDAHFJS6VvY.FnRV3SiDd3Ck8dEx0BGLSmxE052qeRGjnxTv_0G4.Kj.4vFY4ztBDtlKZTLUvEbPZJKDU0CXSTfOEo1C99e3R19SS8Eh_KVToP3Z81_7QWrLzCSfJqXFQUdQLfgUzCJV
 Secret: 6fd5d695882ef63b18bf786be3c8463cdea33e7f
 Session Handle: AMW.zllcRE9V.ztlfxWt0TkfIMCDVue0jurjx1FlIEux4l71mkRv

Error: Invalid auth/bad request (got a 401, expected HTTP/1.1 20X or a redirect)
Error Code: 401
Response: <?xml version="1.0" encoding="UTF-8"?>
<error xml:lang="en-us" yahoo:uri="http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=nfl/teams?oauth_consumer_key=dj0yJmk9cE0yWnZzRVFEbjhFJmQ9WVdrOWNuY3pOVWczTXpJbWNHbzlNQS0tJnM9Y29uc3VtZXJzZWNyZXQmeD1hYw--&amp;amp;oauth_signature_method=HMAC-SHA1&amp;amp;oauth_nonce=209070770059cedbfd9fd1d0.76088688&amp;amp;oauth_timestamp=1506728957&amp;amp;oauth_version=1.0&amp;amp;oauth_token=A%3DUOj1pgHd.AMPSWtSpTpOV7H26tlA5pBx6JFxqZ5t1XDH.Tbat9FvZasADKWuXm9oKKr_vaaWZBRS2RyP4eAmeOEBWFM3HSg1VHrtr8Z9XDhfr_n6b5ujgyFt_Grw8pf5pbfC0x4YelJCH0HDOdmg3tatVsDBLdc79WkQnJ6.4NS2IXBskwpeVGxRpKiH3EYSJ1z_5L6hZQtsegK1jgqsyzezvf6BgJjeOUO84mI175VOX5KY4ht2WE.qzOK21vvxilWlKOT2lTvJdYNH.47B2y.XXqw6WNwfqoIrChVkcr4l_oqE_gzeHlsox6Z1gtl1WgDGeLWqS9iJZqn0AWvbgOk38FVTFkJcYprPthOQBtyLZyom04NVIStnuZ.xc7EEZVKHg88_lHj28uyrbF8ZPD4f3bI0A8nHX6f9Z3ZhgxbSLyG44BiTjAp..Q3qXB45I4gvHqlEferLBwG6T.NHV48XDk3cbf3y7SbtjEaDwr6ityMkp2xMUhqHMJQ4DfxmuRejwadZ0FeK8sqfkZSR2nnQiGN3t61Sla.tf3fFHusbHVEj2Mp2Mk85FL2APWWOtNA6QRSMou38FX5x2YnWYpTkcC9QXxFniWY.eU4lupyVT.KX4hvsc2xBxhbD9zfnGMef1Yg_7w4rlMUbrpAw9JAKtDAHFJS6VvY.FnRV3SiDd3Ck8dEx0BGLSmxE052qeRGjnxTv_0G4.Kj.4vFY4ztBDtlKZTLUvEbPZJKDU0CXSTfOEo1C99e3R19SS8Eh_KVToP3Z81_7QWrLzCSfJqXFQUdQLfgUzCJV&amp;amp;oauth_signature=hU0ugY1YZbcLICWBjd99HVlh7CA%3D" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://www.yahooapis.com/v1/base.rng">
 <description>Invalid cookie, please log in again.</description>
 <detail/>
</error>

Looks like we need to store access token data! Doing that now.


root@dednew:/var/www/fhg# /opt/php-5.6/bin/php tester.php
Got access token information!
 Token: A=UOj1pgHd.AMPSWtSpTpOV7H26tlA5pBx6JFxqZ5t1XDH.Tbat9FvZasADKWuXm9oKKr_vaaWZBRS2RyP4eAmeOEBWFM3HSg1VHrtr8Z9XDhfr_n6b5ujgyFt_Grw8pf5pbfC0x4YelJCH0HDOdmg3tatVsDBLdc79WkQnJ6.4NS2IXBskwpeVGxRpKiH3EYSJ1z_5L6hZQtsegK1jgqsyzezvf6BgJjeOUO84mI175VOX5KY4ht2WE.qzOK21vvxilWlKOT2lTvJdYNH.47B2y.XXqw6WNwfqoIrChVkcr4l_oqE_gzeHlsox6Z1gtl1WgDGeLWqS9iJZqn0AWvbgOk38FVTFkJcYprPthOQBtyLZyom04NVIStnuZ.xc7EEZVKHg88_lHj28uyrbF8ZPD4f3bI0A8nHX6f9Z3ZhgxbSLyG44BiTjAp..Q3qXB45I4gvHqlEferLBwG6T.NHV48XDk3cbf3y7SbtjEaDwr6ityMkp2xMUhqHMJQ4DfxmuRejwadZ0FeK8sqfkZSR2nnQiGN3t61Sla.tf3fFHusbHVEj2Mp2Mk85FL2APWWOtNA6QRSMou38FX5x2YnWYpTkcC9QXxFniWY.eU4lupyVT.KX4hvsc2xBxhbD9zfnGMef1Yg_7w4rlMUbrpAw9JAKtDAHFJS6VvY.FnRV3SiDd3Ck8dEx0BGLSmxE052qeRGjnxTv_0G4.Kj.4vFY4ztBDtlKZTLUvEbPZJKDU0CXSTfOEo1C99e3R19SS8Eh_KVToP3Z81_7QWrLzCSfJqXFQUdQLfgUzCJV
 Secret: 6fd5d695882ef63b18bf786be3c8463cdea33e7f
 Session Handle: AMW.zllcRE9V.ztlfxWt0TkfIMCDVue0jurjx1FlIEux4l71mkRv

Got data from API:

<?xml version="1.0" encoding="UTF-8"?>
<fantasy_content xml:lang="en-US" yahoo:uri="http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=nfl/teams" time="39.669990539551ms" copyright="Data provided by Yahoo! and STATS, LLC" refresh_rate="60" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://fantasysports.yahooapis.com/fantasy/v2/base.rng">
 <users count="1">
  <user>
   <guid>WI3IFMZVEK4K7CINH6WJSKPU7A</guid>
   <games count="1">
    <game>
     <game_key>371</game_key>
     <game_id>371</game_id>
     <name>Football</name>
     <code>nfl</code>
     <type>full</type>
     <url>https://football.fantasysports.yahoo.com/f1</url>
     <season>2017</season>
     <is_registration_over>0</is_registration_over>
     <is_game_over>0</is_game_over>
     <is_offseason>0</is_offseason>
     <teams/>
    </game>
   </games>
  </user>
 </users>
</fantasy_content>

<!-- fanos916.sports.bf1.yahoo.com Fri Sep 29 23:49:19 UTC 2017 -->


Successful!

我不知道发生了什么,并想知道这是否是雅虎问题。

1 个答案:

答案 0 :(得分:0)

我刚开始使用fantasysports.yahooapis.com。我也很挣扎,愿意分享想法。也许我们的代码可以互相帮助。