GetVideos.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. require_once __DIR__ . '/../../vendor/autoload.php'; // change path as needed
  3. use TencentAds\TencentAds;
  4. use TencentAds\Exception\TencentAdsResponseException;
  5. use TencentAds\Exception\TencentAdsSDKException;
  6. /*****
  7. * 本文件提供了一个获取视频(Video)列表的简单示例
  8. */
  9. class GetVideos
  10. {
  11. public static $tads;
  12. public static $ACCESS_TOKEN = 'YOUR ACCESS TOKEN';
  13. public static $ACCOUNT_ID = 'YOUR ACCOUNT ID';
  14. public static $VIDEO_ID = 'YOUR VIDEO ID';
  15. public function init()
  16. {
  17. $tads = TencentAds::init([
  18. 'access_token' => static::$ACCESS_TOKEN,
  19. 'is_debug' => true,
  20. ]);
  21. $tads->useSandbox(); // 默认访问沙箱环境,如访问正式环境,请切换为$tads->useProduction()
  22. static::$tads = $tads;
  23. return $tads;
  24. }
  25. public function main()
  26. {
  27. try {
  28. /* @var TencentAds $tads */
  29. $tads = static::$tads;
  30. $filtering = [
  31. [
  32. 'field' => 'video_id',
  33. 'operator' => 'EQUALS',
  34. 'values' => [static::$VIDEO_ID],
  35. ],
  36. ]; // 过滤条件
  37. $fields = [
  38. 'video_id', 'width', 'height', 'video_frames', 'video_fps', 'video_codec', 'video_bit_rate',
  39. 'audio_codec', 'audio_bit_rate', 'file_size', 'type', 'signature', 'system_status',
  40. 'description', 'preview_url', 'created_time', 'last_modified_time', 'video_profile_name',
  41. 'audio_sample_rate', 'max_keyframe_interval', 'min_keyframe_interval', 'sample_aspect_ratio',
  42. 'audio_profile_name', 'scan_type', 'image_duration_millisecond', 'audio_duration_millisecond',
  43. 'source_type',
  44. ]; // 需要返回的字段
  45. $response = $tads->videos()
  46. ->get([
  47. 'account_id' => static::$ACCOUNT_ID,
  48. 'filtering' => $filtering,
  49. 'fields' => $fields,
  50. ]);
  51. // 从返回里获得Campaigns信息
  52. foreach ($response->getList() as $videoInfo) {
  53. // echo $videoInfo . PHP_EOL;
  54. }
  55. } catch (TencentAdsResponseException $e) {
  56. // When Api returns an error
  57. echo 'Tencent ads returned an error: ' . $e->getMessage() . PHP_EOL;
  58. throw $e;
  59. } catch (TencentAdsSDKException $e) {
  60. // When validation fails or other local issues
  61. echo 'Tencent ads SDK returned an error: ' . $e->getMessage() . PHP_EOL;
  62. throw $e;
  63. } catch (Exception $e) {
  64. echo 'Other exception: ' . $e->getMessage() . PHP_EOL;
  65. throw $e;
  66. }
  67. }
  68. }
  69. if (basename($_SERVER['PHP_SELF']) == basename(__FILE__)) {
  70. try {
  71. $example = new GetVideos();
  72. $example->init();
  73. $example->main();
  74. } catch (\Exception $e) {
  75. exit(-1);
  76. }
  77. }