hitbox.tv api 不能 update_live_media

hitbox.tv api can't update_live_media

目前我正在做一个项目,使用 hitbox.tv api 插件到我的网站。我想在直播期间更新我的视频标题。我使用 guzzle 6 向 api 端点发送 http 请求,以下是我的代码

myGuzzle.php

<?php
namespace myGuzzle;

require __DIR__.'/../vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

class myGuzzle{


    public $params;
    public $method;
    public $endpoint;
    public $body;
    public $status;
    public $errorJson;


    function response($params=[],$method,$endpoint) {

        $this->params = $params;
        $this->method = $method;
        $this->endpoint = $endpoint;
             $client = new Client();
             try{

            $response = $client->request($this->method, $this->endpoint,['json' => $this->params]);

             $this->body = $response->getBody();
             $this->status = $response->getStatusCode();

             }

             catch(ClientException $e){


             $this->body = $e->getMessage();
             $this->status = $e->getCode();
             $this->errorJson = $e->getResponse()->getBody();
                }


    }



     function getStatus(){

         return $this->status;
     }   
     function getBody(){
         return $this->body;

     }
     function getErrorJson(){

         return $this->errorJson;
     }
}

updateLiveMedia.php

namespace models;

use myGuzzle\myGuzzle;

class updateLiveMedia {
    protected $username;
    protected $access_token;
    public $media_user_name;
    public $media_id;
    public $media_category_id;
    public $media_live_delay;
    public $media_hidden;
    public $media_recording;
    public $media_mature;
    public $media_hosted_name;
    public $media_countries = [];
    public $media_status;
    public $media_description;



    function __construct($username,$acessToken) {

        $this->username = $username;
        $this->access_token = $acessToken;
        $this->media_countries = ["EN"];
        $this->media_category_id = '0';
        $this->media_recording = "1";
        $this->media_mature ='0';
        $this->media_user_name = $this->username;
        $this->media_hosted_name = "on";
        $this->media_live_delay='2';
        $this->media_hidden = '0';
    }

    /*
     * Parameters function(title,descritption) or
     * Parameters function(title,description,countries).
     */

    function update($opts=[]){

        if(is_array($opts)){

            foreach($opts as $key=>$value){

                $this->$key = $value;
            }

        }
        $myGuzzle = new myGuzzle;

        $uri = "https://api.hitbox.tv/media/live/".$this->username."?authToken=".$this->access_token;
        $params = ["livestream"=>[
    [
      "media_user_name"=>$this->username,
      "media_id"=>$this->media_id,
      "media_category_id"=>$this->media_category_id,
      "media_live_delay"=>$this->media_live_delay,
      "media_hidden"=>$this->media_hidden,
      "media_recording"=>$this->media_recording,
      "media_mature"=>$this->media_mature,
      "media_hosted_name"=>$this->media_hosted_name,
      "media_countries"=>  $this->media_countries,
      "media_status"=>$this->media_status,
      "media_description"=>$this->media_description,
    ]
  ]];
       $myGuzzle->response($params,"PUT",$uri);
       return $myGuzzle->getBody();
       if($myGuzzle->getStatus() == 200){
           return true;
       }
        return false;

        } 

        }

运行update()return结果如下

{"success":true,"error":false,"message":"host_mode_enabled"}

根据 hitbox.tv (http://developers.hitbox.tv/#update-live-media) 提供的文档,应该 return 类似于以下内容

{
  "livestream": [
    {
      "media_user_name": "masta",
      "media_id": "1",
      "media_category_id": "447",
      "media_live_delay": "0",
      "media_hidden": "0",
      "media_recording": "1",
      "media_mature": "0",
      "media_countries": [
        "EN"
      ],
      "media_status": "This is a stream title!",
      "media_description_md": null
    }
  ]
}

The API documentation for update-live-media 描述了仅当托管标志未被修改时预期的响应。

其他情况会 return 不同类型的答案:

  1. 启用主机模式时

    {"success":true,"error":false,"message":"host_mode_enabled"}

  2. 禁用主机模式时

    {"success":true,"error":false,"message":"host_mode_disabled"}

错误也会 return 与文档不同的东西,例如:

  1. 如果authToken/media_id无效或权限不足

    {"success":true,"error":false,"message":"auth_required_token"} or {"success":true,"error":false,"message":"auth_required"}

当您更新托管模式时,您不会更新任何其他信息(标题)。只需尝试从查询中省略 media_hosted_name,然后观察描述和标题如何更新。用户(和聊天机器人)然后可以看到更新的信息。

如果您在使用 API 时仍有任何问题,请告诉我。我需要一个具体的例子,可以进一步帮助你。