【问题标题】:Issues creating, updating and retrieving data from Wowza Streaming Engine using PHP REST API?使用 PHP REST API 从 Wowza Streaming Engine 创建、更新和检索数据时遇到问题?
【发布时间】:2019-05-15 14:03:00
【问题描述】:

我开始使用 Wowza PHP 库,但无法连接到本地安装的流媒体引擎。按照https://github.com/WowzaMediaSystems/wse-rest-library-php 的指示,我安装了composer,使用我的服务器主机和身份验证设置创建了配置文件

wowza_config.php

define("WOWZA_HOST","http://localhost:8087/v2");
define("WOWZA_SERVER_INSTANCE", "_defaultServer_");
define("WOWZA_VHOST_INSTANCE", "_defaultVHost_");
define("WOWZA_USERNAME", "admin");
define("WOWZA_PASSWORD", "admin");

然后在尝试测试以从服务器检索数据时:

index.php

<?php


require_once ('vendor/autoload.php');
require_once("config/wowza_config.php");


// It is simple to create a setup object for transporting our settings
$setup = new Com\Wowza\Entities\Application\Helpers\Settings();
$setup->setHost(WOWZA_HOST);
$setup->setUsername(WOWZA_USERNAME);
$setup->setPassword(WOWZA_PASSWORD);

$sf = new Com\Wowza\Statistics($setup);
// get stats per application
$wowzaApplication = new Com\Wowza\Application($setup, 'vod');
// get total server stats
$server = new Com\Wowza\Server($setup, 'http://localhost:8087/v2');
$response = $sf->getServerStatistics($server);
// get stats historical for given application
// $response = $sf->getApplicationStatisticsHistory($wowzaApplication);
// $response = $sf->getApplicationStatistics($wowzaApplication);
// get incoming stream stats for given application


var_dump($response);
?>

我得到了错误

object(stdClass)#8 (4) { ["message"]=> string(40) "The request requires user authentication" ["code"]=> string(3) "401" ["wowzaServer"]=> string(5) "4.7.7" ["success"]=> bool(false) } 

我已经三重检查以确认我使用的凭据与服务器的凭据匹配,但无法弄清楚我做错了什么

【问题讨论】:

  • 是致命错误:通过查看source code 几秒钟,您可以看出应用构造函数需要将很多参数传递给它。
  • 至于另一个错误,与示例相比,您可能做错了什么(例如,没有提供用户名/密码,或者使用了无效的凭据),但我们无法确定,因为您没有'不要向我们展示你的代码,它会产生那个错误。
  • 嗨@ADyson,感谢您的回复,我基本上是从示例中复制和粘贴的,只是对服务器凭据进行了修改。您看到的代码是我试图运行的代码。我确实解决了参数问题,但身份验证位仍然让我望而却步。我提供了 wowza 服务器的管理员凭据,但它仍然拒绝它们
  • 在“如您所见”的代码中,您没有将凭据(在 Settings 对象中)传递给 Application 构造函数。我们可以看到的代码是导致致命错误的代码。我们看不到导致身份验证问题的版本......上面的代码不会那么远。所以是的,请告诉我们导致第二个错误的代码,谢谢。
  • 嗨@ADyson,我通过传递凭据更正了错误。我有我使用的测试脚本和我的配置

标签: php wowza


【解决方案1】:

我注意到一件事:在您的设置中,您没有为“useDigest”设置值。所以它默认为 false(参见https://github.com/WowzaMediaSystems/wse-rest-library-php/blob/master/src/Entities/Application/Helpers/Settings.php)。然后,当您调用 getServerStatistics() 时,它最终会在 Wowza 类中调用“sendRequest()”(参见 https://github.com/WowzaMediaSystems/wse-rest-library-php/blob/master/src/Wowza.php)。而在这个类中,只有在设置中将“useDigest”设置为true时,才会在请求中添加用户名和密码:

if ($this->settings->isUseDigest()) {
   curl_setopt($ch, CURLOPT_USERPWD, $this->settings->getUsername() . ':' . $this->settings->getPassword());
   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
}

所以我认为它根本没有将用户名和密码附加到您的请求中。

所以我建议你添加

$setup->setUseDigest(true);

在您配置 Settings 对象时添加到您的代码中,这应该会有所帮助。

【讨论】:

  • 感谢@ADyson。感谢帮助
猜你喜欢
  • 2015-04-19
  • 1970-01-01
  • 1970-01-01
  • 2019-12-24
  • 1970-01-01
  • 2020-12-01
  • 2018-06-17
  • 1970-01-01
  • 2021-06-29
相关资源
最近更新 更多