7

我正在使用新的 Amazon ElasticTranscoder 服务,并且不熟悉使用 AWS-SDK。我创建了一个运行createJob请求的成功脚本,将 Amazon S3 文件从一种格式转码为另一种格式。

问题是,我似乎无法访问$data发出请求时返回的响应。我可以看到它,它包含我需要的信息,但是当我尝试存储它时收到此错误:

Fatal error: Cannot access protected property 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 处理响应请求的文档,非常感谢任何帮助。

4

1 回答 1

24

你有两个选择:

  1. 使用文档toArray()中“继承自的方法Guzzle\Common\Collection”下列出的方法。

    例如

    $webm_transcode_request->toArray();
    
  2. 只需直接访问$data属性的索引,就好像它们是响应对象的索引一样。这是有效的,因为Guzzle\Service\Resource\Model该类实现了 PHP 的魔术ArrayAccess接口以使类似数组的访问对$data属性进行操作。

    例如

    $response = $ec2Client->describeInstances();
    
    // Gets the value of the 'Reservations' key of the protected `$data` property
    // of `$response`
    var_dump($response['Reservations']);
    
于 2013-03-23T20:13:45.020 回答