du94414 2019-05-22 07:22
浏览 114

用PHP传递body头

I'm trying make a Vimeo-API to upload subtitles/captions, following this guide: https://developer.vimeo.com/api/upload/texttracks#uploading-a-text-track-step-3

The guide gives 4 steps, I'm stalled in step 3.

Step 3: To upload the text track, take the value of the link field from Step 2, and make a PUT request to this location: PUT https://api.vimeo.com{link}

Here is my code:

require 'Vimeo/autoload.php';
use Vimeo\Vimeo;

$client = new Vimeo("xxxxxxxxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxxx,xxxxxxxxxxxxx");


include __DIR__ . '/Vimeo/autoload.php';

$clientId = "xxxxxxxxxxxxxxxxxxxxx";
$clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxx";
$scope = "public";
$userId = 9999999;
$lib = new \Vimeo\Vimeo($clientId, $clientSecret);
$token = $lib->clientCredentials($scope);


$lib->setToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxx');


$videos = $lib->request("/videos/99999999/texttracks", ["type"=>"captions", "language"=>"pt-BR", "name"=>"legenda"], "POST");
$link = $videos["body"]["link"];
$videos = $lib->request("/videos/99999999/texttracks/", ["link"=>$link, "body"=>"https://paste.ee/r/E3Q1K/0"], "PUT");

echo "<pre>".var_export($videos, true)."</pre>";

Output:

array (
  'body' => NULL,
  'status' => 405,
  'headers' => 
  array (
    'Server' => 'nginx',
    'Content-Type' => 'application/json',
    'Allow' => 'GET,POST,OPTIONS',
    'X-Vimeo-DC' => 'ge',
    'Accept-Ranges' => 'bytes',
    'Via' => '1.1 varnish',
    'Content-Length' => '0',
    'Date' => 'Wed, 22 May 2019 07:11:58 GMT',
    'Connection' => 'keep-alive',
    'X-Served-By' => 'cache-bwi5150-BWI, cache-lax8642-LAX',
    'X-Cache' => 'MISS, MISS',
    'X-Cache-Hits' => '0, 0',
    'X-Timer' => 'S1558509118.323164,VS0,VE80',
    'Vary' => 'Accept-Encoding',
  ),
)   

So, the problem occur in this line: $videos = $lib->request("/videos/99999999/texttracks/", ["link"=>$link, "body"=>"https://paste.ee/r/E3Q1K/0"], "PUT"); As you can see, the output body is NULL. How can I set up correctly body header? I'm trying make this API for three days, here is my last hope, I'll be very glad if you could help me.

Thank you

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 组策略中的计算机配置策略无法下发
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)