本文为您介绍如何使用视频点播服务端 PHP SDK 将音频、视频、图片等媒资文件上传至视频点播服务。
媒资上传到视频点播中会产生存储费用,具体参见媒资存储计费。
视频点播服务端 SDK 封装了 ApplyUploadInfo - 获取上传地址和凭证和 CommitUploadInfo - 确认上传接口以及上传逻辑,您只需简单配置即可进行上传。
说明
<?php require('../../vendor/autoload.php'); use Volc\Service\Vod\Models\Request\VodUploadMediaRequest; use Volc\Service\Vod\Models\Response\VodCommitUploadInfoResponse; use Volc\Service\Vod\Upload\Functions; use Volc\Service\Vod\Upload\VodUpload; use Volc\Service\Vod\Upload\OptionInfo; use Volc\Service\Vod\Upload\Template; // Create a VOD instance in the specified region. // $client = Volc\Service\Vod\Vod::getInstance('cn-north-1'); $client = VodUpload::getInstance(); // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408. // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed. // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account. // $client->setAccessKey('your ak'); // $client->setSecretKey('your sk'); $space = 'your space'; $filePath = "file path"; $functions = new Functions(); $functions->addGetMetaFunc(); $functions->addSnapshotTimeFunc(2.1); $impTemplate = new Template(); $impTemplate->TemplateIds = ["imp template id"]; $impTemplate->TemplateType = "imp"; $transcodeTemplate = new Template(); $transcodeTemplate->TemplateIds = ["transcode template id"]; $transcodeTemplate->TemplateType = "transcode"; $functions->addStartWorkflowTemplateFunc([$impTemplate, $transcodeTemplate]); $optionInfo = new OptionInfo(); $optionInfo->IsHlsIndexOnly = true; $functions->addOptionInfoFunc($optionInfo); $functions = $functions->getFunctionsString(); $request = new VodUploadMediaRequest(); $request->setSpaceName($space); $request->setFilePath($filePath); $request->setFunctions($functions); $request->setCallbackArgs("my callback"); $request->setFileName("hello/vod.mp4"); $request->setStorageClass(1); $request->setUploadHostPrefer(""); $response = new VodCommitUploadInfoResponse(); try { $response = $client->uploadMedia($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { echo $response->getResponseMetadata()->getError()->serializeToJsonString(), "\n"; } echo $response->serializeToJsonString(); echo "\n"; if ($response->getResult() != null) { echo $response->getResult()->getData()->getVid(), "\n"; echo $response->getResult()->getData()->getPosterUri(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n"; }
视频点播服务端 SDK 封装了 URL 批量拉取上传 - UploadMediaByUrl 接口,您只需简单配置即可进行上传。完整的上传流程请见服务端上传。
说明
<?php require('../../vendor/autoload.php'); // Create a VOD instance in the specified region. // $client = Vod::getInstance('cn-north-1'); $client = Volc\Service\Vod\Vod::getInstance(); // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408. // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed. // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account. // $client->setAccessKey('your ak'); // $client->setSecretKey('your sk'); $request = new Volc\Service\Vod\Models\Request\VodUrlUploadRequest(); $request->setSpaceName("your SpaceName"); $urlSet = new Volc\Service\Vod\Models\Business\VodUrlUploadURLSet(); $urlSet->setSourceUrl(""); $urlSet->setStorageClass(1); $urlSet->setFileExtension(".mp4"); $urlSet->setCallbackArgs(""); $customHeaders = ['your header key' => "your header value"]; // 自定义 Header,业务希望访问源视频 URL 携带的 Header(例如User-Agent)可以通过该参数传入,非必须字段 $urlSet->setCustomURLHeaders($customHeaders); $request->setURLSets([$urlSet]); $response = new Volc\Service\Vod\Models\Response\VodUrlUploadResponse(); try { $response = $client->uploadMediaByUrl($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response != null && $response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { echo $response->getResponseMetadata()->getError()->serializeToJsonString(), "\n"; } else { echo $response->serializeToJsonString(), "\n"; }
视频点播服务端 SDK 封装了 ApplyUploadInfo - 获取上传地址和凭证和 CommitUploadInfo - 确认上传接口以及上传逻辑,您只需简单配置即可进行上传。
说明
<?php require('../../vendor/autoload.php'); use Volc\Service\Vod\Models\Request\VodUploadMaterialRequest; use Volc\Service\Vod\Models\Response\VodCommitUploadInfoResponse; use Volc\Service\Vod\Upload\Functions; use Volc\Service\Vod\Upload\VodUpload; use Volc\Service\Vod\Upload\OptionInfo; // Create a VOD instance in the specified region. // $client = Volc\Service\Vod\Vod::getInstance('cn-north-1'); $client = VodUpload::getInstance(); // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408. // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed. // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account. // $client->setAccessKey('your ak'); // $client->setSecretKey('your sk'); $space = 'your space'; $filePath = "file path"; //音视频素材上传 $functions = new Functions(); $functions->addGetMetaFunc(); $functions->addSnapshotTimeFunc(2.1); $optionInfo = new OptionInfo(); $optionInfo->Title = '素材测试视频'; $optionInfo->Tags = 'test'; $optionInfo->Description = '素材测试,视频文件'; $optionInfo->Category = 'video'; $optionInfo->RecordType = 2; $optionInfo->Format = 'mp4'; $functions->addOptionInfoFunc($optionInfo); $functions = $functions->getFunctionsString(); $request = new VodUploadMaterialRequest(); $request->setSpaceName($space); $request->setFilePath($filePath); $request->setFunctions($functions); $request->setFileType("media"); $request->setCallbackArgs("my callback"); $request->setUploadHostPrefer(""); $response = new VodCommitUploadInfoResponse(); try { $response = $client->uploadMaterial($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { echo $response->getResponseMetadata()->getError(), "\n"; } echo $response->serializeToJsonString(); echo "\n"; if ($response->getResult() != null) { echo $response->getResult()->getData()->getMid(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n"; } ////图片素材上传 //$functions = new Functions(); //$functions->addGetMetaFunc(); // //$optionInfo = new OptionInfo(); //$optionInfo->Title = '素材测试图片'; //$optionInfo->Tags = 'test'; //$optionInfo->Description = '素材测试,图片文件'; //$optionInfo->Category = 'image'; //$optionInfo->RecordType = 2; //$optionInfo->Format = 'jpg'; //$functions->addOptionInfoFunc($optionInfo); // //$functions = $functions->getFunctionsString(); // //$request = new VodUploadMaterialRequest(); //$request->setSpaceName($space); //$request->setFilePath($filePath); //$request->setFunctions($functions); //$request->setFileType("image"); //$request->setFileName("hello/vod/image"); // //$request->setCallbackArgs("my callback"); // //$response = new VodCommitUploadInfoResponse(); //try { // $response = $client->uploadMaterial($request); //} catch (Exception $e) { // echo $e, "\n"; //} catch (Throwable $e) { // echo $e, "\n"; //} //if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { // echo $response->getResponseMetadata()->getError(), "\n"; //} //echo $response->serializeToJsonString(); //echo "\n"; // //if ($response->getResult() != null) { // echo $response->getResult()->getData()->getMid(), "\n"; // echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n"; // echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n"; //} ////字幕素材上传 //$functions = new Functions(); //$functions->addGetMetaFunc(); // //$optionInfo = new OptionInfo(); //$optionInfo->Title = '素材测试字幕'; //$optionInfo->Tags = 'test'; //$optionInfo->Description = '素材测试,字幕文件'; //$optionInfo->Category = 'subtitle'; //$optionInfo->RecordType = 2; //$optionInfo->Format = 'vtt'; //$functions->addOptionInfoFunc($optionInfo); // //$functions = $functions->getFunctionsString(); // //$request = new VodUploadMaterialRequest(); //$request->setSpaceName($space); //$request->setFilePath($filePath); //$request->setFunctions($functions); //$request->setFileType("object"); //$request->setFileName("hello/vod/object"); // //$request->setCallbackArgs("my callback"); // //$response = new VodCommitUploadInfoResponse(); //try { // $response = $client->uploadMaterial($request); //} catch (Exception $e) { // echo $e, "\n"; //} catch (Throwable $e) { // echo $e, "\n"; //} //if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { // echo $response->getResponseMetadata()->getError(), "\n"; //} //echo $response->serializeToJsonString(); //echo "\n"; // //if ($response->getResult() != null) { // echo $response->getResult()->getData()->getMid(), "\n"; // echo $response->getResult()->getData()->getSourceInfo()->getSize(), "\n"; //}
您可以通过配置上传事件通知及时获取上传的进展和状态,详细介绍请见上传事件通知。
您可以通过工作流实现上传后自动转码,详细介绍请见工作流。
音视频资源上传至视频点播服务之后,默认为未发布状态,此时无法获取到播放地址。因此在音视频播放前,您需要先修改音视频状态为已发布。具体操作请参见修改音视频发布状态。
FileName
参数设置了文件名称,但上传后控制台显示"未命名",为什么没有显示我设置的文件名称?这是因为在视频点播服务中,FileName
参数实际上指的是文件路径(即媒资在存储桶中的唯一标识和存储位置),而不是用户可见的文件名称。如需设置控制台显示的文件名称,您需要通过上传功能函数设置 FileTitle
参数。详见上传功能函数说明。
参数 | 说明 |
---|---|
FileType |
|
RecordType |
|
Category |
|
通过正确组合这三个参数,可确保文件上传至正确的域名并生成匹配的元数据。示例:
FileType
设为 media
或留空。RecordType
设为 1
或留空。Category
无需设置(仅当 RecordType=2
时生效)。FileType
设为 image
(图片使用图片上传域名)。RecordType
设为 2
(素材)。Category
设为 image
(进一步指定为图片素材)。FileType
设为 object
(非音视频/图片的文件类型)。RecordType
设为 2
(素材)。Category
设为 subtitle
(进一步指定为字幕素材)。说明
通过服务端 SDK 上传素材时,接口已默认设置 RecordType
为 2,用户无需再设置。
视频点播当前仅支持手动分类。您可在视频点播控制台指定空间内的分类管理页面创建分类并获取分类 ID,具体请见分类管理。
如果您使用客户端上传 SDK 进行上传,您需要在应用服务端通过 AK 和 SK 在本地签出临时上传 Token,不依赖外网。如希望同时生成多个临时上传 Token,您可以循环调用生成方法。更多信息,请见客户端上传。
<?php require('../../vendor/autoload.php'); use Volc\Service\Vod\Vod; use Volc\Service\Vod\Upload\UploadPolicy; // Create a VOD instance in the specified region. // $client = Volc\Service\Vod\Vod::getInstance('cn-north-1'); $client = Volc\Service\Vod\Vod::getInstance(); // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408. // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed. // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account. // $client->setAccessKey('your ak'); // $client->setSecretKey('your sk'); $expire = 60*60; // 请求的签名有效期 echo "\nSTS2鉴权签名\n"; // 使用 $spaces 来限制限制允许上传的空间 //$spaces = ['']; // 使用 $keyPtn 来限制上传的FileName路径 // 如: "test/*" 表示上传的文件必须包含 "test/" 前缀 //$keyPtn = ''; // 使用 $uploadPolicy来设置上传策略 //$uploadPolicy = new UploadPolicy(); //$uploadPolicy->ContentTypeBlackList = ['content-type1','content-type2']; //$uploadPolicy->ContentTypeWhiteList = ['content-type1','content-type2']; //$uploadPolicy->FileSizeUpLimit = 'file size'; //$uploadPolicy->FileSizeBottomLimit = 'file size'; //$response = $client->getUploadVideoAuthWithExpiredTime($expire, $spaces, $keyPtn, $uploadPolicy); $response = $client->getUploadVideoAuthWithExpiredTime($expire); echo json_encode($response); echo "\nSTS2鉴权签名,过期时间默认1小时\n"; $vid = ""; $response = $client->getUploadVideoAuth(); echo json_encode($response);
接口请求参数和返回参数说明详见 ApplyUploadInfo。
<?php require('../../vendor/autoload.php'); // Create a VOD instance in the specified region. // $client = Volc\Service\Vod\Vod::getInstance('cn-north-1'); $client = Volc\Service\Vod\Vod::getInstance(); // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408. // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed. // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account. // $client->setAccessKey('your ak'); // $client->setSecretKey('your sk'); $request = new Volc\Service\Vod\Models\Request\VodApplyUploadInfoRequest(); $request->setSpaceName("your SpaceName"); $request->setSessionKey("your SessionKey"); $request->setFileSize(0); $request->setFileType("your FileType"); $request->setFileName("your FileName"); $request->setStorageClass(1); $request->setFileExtension("your FileExtension"); $request->setClientNetWorkMode("your ClientNetWorkMode"); $request->setClientIDCMode("your ClientIDCMode"); $request->setNeedFallback(false); $request->setUploadHostPrefer("your UploadHostPrefer"); $response = new Volc\Service\Vod\Models\Response\VodApplyUploadInfoResponse(); try { $response = $client->applyUploadInfo($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response != null && $response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { echo $response->getResponseMetadata()->getError()->serializeToJsonString(), "\n"; } else { echo $response->serializeToJsonString(), "\n"; }
接口请求参数和返回参数详见 OpenAPI:查询 URL 批量上传任务状态。
<?php require('../vendor/autoload.php'); use Volc\Service\Vod\Models\Business\VodURLSet; use Volc\Service\Vod\Models\Request\VodQueryUploadTaskInfoRequest; use Volc\Service\Vod\Models\Response\VodQueryUploadTaskInfoResponse; use Volc\Service\Vod\Vod; // Create a VOD instance in the specified region. // $client = Vod::getInstance('cn-north-1'); $client = Vod::getInstance(); // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408. // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed. // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account. // $client->setAccessKey('your ak'); // $client->setSecretKey('your sk'); $jobId = 'url jobId'; $jobIds = [$jobId]; $request = new VodQueryUploadTaskInfoRequest(); $request->setJobIds(implode(",", $jobIds)); $response = new VodQueryUploadTaskInfoResponse(); try { $response = $client->queryUploadTaskInfo($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response->getResponseMetadata()->getError() != null) { print_r($response->getResponseMetadata()->getError()); } echo $response->serializeToJsonString(); echo "\n"; $mediaInfo = new VodURLSet(); $mediaInfo = $response->getResult()->getData()->getMediaInfoList()[0]; echo $mediaInfo->getRequestId(), "\n"; echo $mediaInfo->getState(), "\n";
接口请求参数和返回参数说明详见 ApplyUploadInfo 及 CommitUploadInfo。
<?php require('../vendor/autoload.php'); use Volc\Service\Vod\Models\Request\VodUploadMediaRequest; use Volc\Service\Vod\Models\Response\VodCommitUploadInfoResponse; use Volc\Service\Vod\Upload\Functions; use Volc\Service\Vod\Upload\VodUpload; // Create a VOD instance in the specified region. // $client = Vod::getInstance('cn-north-1'); $client = VodUpload::getInstance(); // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408. // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed. // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account. // $client->setAccessKey('your ak'); // $client->setSecretKey('your sk'); $space = 'your space'; $filePath = "file path"; Functions::addGetMetaFunc(); Functions::addSnapshotTimeFunc(2.1); $functions = Functions::getFunctionsString(); $request = new VodUploadMediaRequest(); $request->setSpaceName($space); $request->setFilePath($filePath); $request->setFunctions($functions); $request->setCallbackArgs("my callback"); $response = new VodCommitUploadInfoResponse(); try { $response = $client->uploadMedia($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response->getResponseMetadata()->getError() != null) { print_r($response->getResponseMetadata()->getError()); } echo $response->serializeToJsonString(); echo "\n"; echo $response->getResult()->getData()->getVid(), "\n"; echo $response->getResult()->getData()->getPosterUri(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n";
接口请求参数和返回参数说明详见 ApplyUploadInfo 及 CommitUploadInfo。
<?php require('../../vendor/autoload.php'); use Volc\Service\Vod\Models\Request\VodUploadMaterialRequest; use Volc\Service\Vod\Models\Response\VodCommitUploadInfoResponse; use Volc\Service\Vod\Upload\Functions; use Volc\Service\Vod\Upload\VodUpload; use Volc\Service\Vod\Upload\OptionInfo; // Create a VOD instance in the specified region. // $client = Vod::getInstance('cn-north-1'); $client = VodUpload::getInstance(); // Configure your Access Key ID (AK) and Secret Access Key (SK) in the environment variables or in the local ~/.volc/config file. For detailed instructions, see https://www.volcengine.com/docs/4/4408. // The SDK will automatically fetch the AK and SK from the environment variables or the ~/.volc/config file as needed. // During testing, you may use the following code snippet. However, do not store the AK and SK directly in your project code to prevent potential leakage and safeguard the security of all resources associated with your account. // $client->setAccessKey('your ak'); // $client->setSecretKey('your sk'); $space = 'your space'; $filePath = "file path"; //音视频素材上传 Functions::addGetMetaFunc(); Functions::addSnapshotTimeFunc(2.1); $optionInfo = new OptionInfo(); $optionInfo->Title = '素材测试视频'; $optionInfo->Tags = 'test'; $optionInfo->Description = '素材测试,视频文件'; $optionInfo->Category = 'video'; $optionInfo->RecordType = 2; $optionInfo->Format = 'mp4'; Functions::addOptionInfoFunc($optionInfo); $functions = Functions::getFunctionsString(); $request = new VodUploadMaterialRequest(); $request->setSpaceName($space); $request->setFilePath($filePath); $request->setFunctions($functions); $request->setFileType("media"); $request->setCallbackArgs("my callback"); $response = new VodCommitUploadInfoResponse(); try { $response = $client->uploadMaterial($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { echo $response->getResponseMetadata()->getError(), "\n"; } echo $response->serializeToJsonString(); echo "\n"; if ($response->getResult() != null) { echo $response->getResult()->getData()->getMid(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n"; } //图片素材上传 Functions::addGetMetaFunc(); $optionInfo = new OptionInfo(); $optionInfo->Title = '素材测试图片'; $optionInfo->Tags = 'test'; $optionInfo->Description = '素材测试,图片文件'; $optionInfo->Category = 'image'; $optionInfo->RecordType = 2; $optionInfo->Format = 'jpg'; Functions::addOptionInfoFunc($optionInfo); $functions = Functions::getFunctionsString(); $request = new VodUploadMaterialRequest(); $request->setSpaceName($space); $request->setFilePath($filePath); $request->setFunctions($functions); $request->setFileType("image"); $request->setCallbackArgs("my callback"); $response = new VodCommitUploadInfoResponse(); try { $response = $client->uploadMaterial($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { echo $response->getResponseMetadata()->getError(), "\n"; } echo $response->serializeToJsonString(); echo "\n"; if ($response->getResult() != null) { echo $response->getResult()->getData()->getMid(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getWidth(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getHeight(), "\n"; } //字幕素材上传 Functions::addGetMetaFunc(); $optionInfo = new OptionInfo(); $optionInfo->Title = '素材测试字幕'; $optionInfo->Tags = 'test'; $optionInfo->Description = '素材测试,字幕文件'; $optionInfo->Category = 'subtitle'; $optionInfo->RecordType = 2; $optionInfo->Format = 'vtt'; Functions::addOptionInfoFunc($optionInfo); $functions = Functions::getFunctionsString(); $request = new VodUploadMaterialRequest(); $request->setSpaceName($space); $request->setFilePath($filePath); $request->setFunctions($functions); $request->setFileType("object"); $request->setCallbackArgs("my callback"); $response = new VodCommitUploadInfoResponse(); try { $response = $client->uploadMaterial($request); } catch (Exception $e) { echo $e, "\n"; } catch (Throwable $e) { echo $e, "\n"; } if ($response->getResponseMetadata() != null && $response->getResponseMetadata()->getError() != null) { echo $response->getResponseMetadata()->getError(), "\n"; } echo $response->serializeToJsonString(); echo "\n"; if ($response->getResult() != null) { echo $response->getResult()->getData()->getMid(), "\n"; echo $response->getResult()->getData()->getSourceInfo()->getSize(), "\n"; }