我正在使用新的 Amazon ElasticTranscoder 服务,并且是 AWS-SDK 的新手。我创建了一个成功的脚本,该脚本运行 createJob
请求,将 Amazon S3 文件从一种格式转码为另一种格式。
问题是,我似乎无法访问发出请求时返回的响应 $data
。我可以看到它,它包含我需要的信息,但是当我尝试存储它时收到此错误:
fatal error :无法访问 protected 属性 Guzzle\Service\Resource\Model::$data
这是我的请求:
<?php
// Include the SDK
require 'aws.phar';
use Aws\ElasticTranscoder\ElasticTranscoderClient;
// Setup the trancoding service tool(s)
$client = ElasticTranscoderClient::factory( array(
'key' => 'XXXXXXXXX',
'secret' => 'XXXXXXXXX',
'region' => 'us-east-1'
) );
// Create a new transcoding job
$file_name = '1362761118382-lqg0CvC1Z1.mov';
$file_name_explode = explode( '.', $file_name );
$webm_transcode_request = $client->createJob( array(
'PipelineId' => '1362759955061-7ad779',
'Input' => array(
'Key' => $file_name,
'FrameRate' => 'auto',
'Resolution' => 'auto',
'AspectRatio' => 'auto',
'Interlaced' => 'auto',
'Container' => 'auto',
),
'Output' => array(
'Key' => $file_name_explode[0] . '.webm',
'ThumbnailPattern' => $file_name_explode[0] . '-thumb-{resolution}-{count}',
'Rotate' => '0',
'PresetId' => '1363008701532-b7d529' // BenchFly MP4
)
) );
// Print the response data
echo '<pre>';
var_dump( $webm_transcode_request->data );
echo '</pre>';
?>
我一直在努力寻找有关使用 PHP 和 AWS SDK 处理响应请求的文档,非常感谢任何帮助。
最佳答案
你有两个选择:
使用
toArray()
方法,在 the docs 中的“继承自Guzzle\Common\Collection
的方法”下列出.例如
$webm_transcode_request->toArray();
只需直接访问
$data
属性的索引,就像它们是响应对象的索引一样。这是有效的,因为Guzzle\Service\Resource\Model
类实现了 PHP 的魔法ArrayAccess
对$data
属性进行类数组访问操作的接口(interface)。例如
$response = $ec2Client->describeInstances(); // Gets the value of the 'Reservations' key of the protected `$data` property // of `$response` var_dump($response['Reservations']);
关于php - 从适用于 PHP 的 AWS 开发工具包提取 protected 请求响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15553974/