【问题标题】:Twitch API - follow a user, getting "411 Length Required" errorTwitch API - 关注用户,收到“需要 411 长度”错误
【发布时间】:2014-11-15 15:52:07
【问题描述】:

所以我正在为一个希望在他的社交网站上使用一个简单功能的客户编写一个功能,以便用户可以在 Twitch 上关注频道,没有 SDK,我有以下功能:

function twitch_follow_channel($user, $channel, $client_id, $access_token) {

      $ch = curl_init();
            curl_setopt($ch, CURLOPT_PUT, true);
            curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLINFO_HEADER_OUT, true);
            curl_setopt($ch, CURLOPT_URL, 'https://api.twitch.tv/kraken/users/'.$user.'/follows/channels/'.$channel.'?oauth_token='.$access_token);  
            $h = 'Client-ID: '.$client_id.', Accept: application/vnd.twitchtv.v3+json, Authorization: OAuth '. $access_token;
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth '.$access_token,
                                                       'Client-ID: '.$client_id,
                                                       'Content-Length: '.strlen($h), 
                                                       'Accept: application/vnd.twitchtv.v3+json'));    
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); 
      $r  = curl_exec($ch);
      $ci = curl_getinfo($ch);
      r($ci);
      r($r);
      return json_decode($r, true);       

}

我在 HTTP HEADER 中包含 Content-length 我不知道我缺少什么

注意事项

  • 访问令牌具有user_follows_edit 范围。
  • 使用r() 代替var_dump()
  • 我已经知道 GitHub 上的DOCs,请仔细关注

【问题讨论】:

    标签: php api curl oauth-2.0 twitch


    【解决方案1】:

    最近我自己也这样做了,你补充一下如何:

     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 
    

    这样你说 CURL 使用 PUT 作为请求。

    要取消关注,只需将 PUT 替换为 DELETE 和您的 gucci。

    Atom8tik

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多