PHP CallFire SDK-身份验证和请求/响应问题
免责声明:php新手学生在这里学习非常努力 我正在尝试构建一个应用程序,它可以与用户交互 在这一点上,我试图实现的就是与API建立通信,并成功地进行请求/响应循环 我已经在XAMPP本地服务器上安装了CallFireSDK与Composer的依赖关系。我想要运行非常基本的示例:它实例化API,发送请求并解析响应PHP CallFire SDK-身份验证和请求/响应问题,php,sdk,composer-php,callfire,Php,Sdk,Composer Php,Callfire,免责声明:php新手学生在这里学习非常努力 我正在尝试构建一个应用程序,它可以与用户交互 在这一点上,我试图实现的就是与API建立通信,并成功地进行请求/响应循环 我已经在XAMPP本地服务器上安装了CallFireSDK与Composer的依赖关系。我想要运行非常基本的示例:它实例化API,发送请求并解析响应 <?php use CallFire\Api\Rest\Request; require 'vendor/autoload.php'; $client = CallFire\Ap
<?php
use CallFire\Api\Rest\Request;
require 'vendor/autoload.php';
$client = CallFire\Api\Client::Rest("<api-login>", "<api-password>", "Broadcast"); //I'm using my valid CallFire API keys here.
$request = new Request\QueryBroadcasts;
$response = $client->QueryBroadcasts($request); //LINE 10
$broadcasts = $client::response($response);
foreach($broadcasts as $broadcast) {
var_dump($broadcast);
}
AbstractClient.php中的第59行是
public static function response($data, $type = self::FORMAT_XML)
{
if (is_string($data) && strlen($data) === 0) {
return true; // Many operations return an empty string for success
}
switch ($type) {
case static::FORMAT_XML:
return AbstractResponse::fromXml($data); // LINE 59
case static::FORMAT_JSON:
return AbstractResponse::fromJson($data);
}
throw new InvalidArgumentException("Type must be 'xml' or 'json'");
}
Response.php中的第39行和第50行是
public static function fromXml($document)
{
$document = static::getXmlDocument($document);
// return print_r($document);
switch ($document->firstChild->nodeName) { // LINE 39 error for this line is Notice: Trying to get property of non-object
case 'r:ResourceList':
return Response\ResourceList::fromXml($document);
case 'r:Resource':
return Response\Resource::fromXml($document);
case 'r:ResourceReference':
return Response\ResourceReference::fromXml($document);
case 'r:ResourceException':
return Response\ResourceException::fromXml($document);
}
throw new UnexpectedValueException('Response type not recognized'); // LINE 50: this is what throws the fatal error exception
}
第10行在示例代码中突出显示
所以我知道API正在发回一个类型不明的响应。为什么,如果我真的在使用SDK和文档中的一个基本示例?我如何检查我得到的响应,以了解它到底是什么?我尝试在response.php文件中使用r_print打印响应,但在浏览器中打印了一个“1”。这对我来说毫无意义。是因为我在浏览器中运行此程序吗?已解决:在本地主机环境中运行该程序导致了问题。一旦我将应用程序上传到服务器上,一切都正常了
public static function fromXml($document)
{
$document = static::getXmlDocument($document);
// return print_r($document);
switch ($document->firstChild->nodeName) { // LINE 39 error for this line is Notice: Trying to get property of non-object
case 'r:ResourceList':
return Response\ResourceList::fromXml($document);
case 'r:Resource':
return Response\Resource::fromXml($document);
case 'r:ResourceReference':
return Response\ResourceReference::fromXml($document);
case 'r:ResourceException':
return Response\ResourceException::fromXml($document);
}
throw new UnexpectedValueException('Response type not recognized'); // LINE 50: this is what throws the fatal error exception
}