我发送带有以下标头的“ playlistItems”请求:
array(5) {
[0]=>
string(29) "Content-Type:application/json"
[1]=>
string(153) "Authorization:Bearer [hidden]"
[2]=>
string(33) "X-JavaScript-User-Agent:Automator"
[3]=>
string(66) "If-Match:"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/AtpZMDGfwUXtVHbcH_1spJYn8eg""
[4]=>
string(71) "If-None-Match:"Bdx4f4ps3xCOOo1WZ91nTLkRZ_c/AtpZMDGfwUXtVHbcH_1spJYn8eg""
}
但是我收到的ETag不同,内容没有变化。
Youtube V3真的支持ETag吗?或标题错误?
我不使用任何官方图书馆。我的代码使用PHP和Curl。
$this->execute(
"playlistItems",
array("part"=>"id,snippet","playlistId"=>$channelId)
,$etag
);
和
public function execute($source, $options, $etag = null)
{
if (count($options)==0) {
$url=$this->base_url.$source;
} else {
$vars=array();
foreach ($options as $key => $value) {
$vars[]=$key."=".urlencode($value);
}
$vars=implode("&", $vars);
$url=$this->base_url.$source."?".$vars;
}
$httpheader=array(
'Content-Type'=>'application/json',
'Authorization'=>'Bearer ' . $this->token,
'X-JavaScript-User-Agent'=>'Automator'
);
if ($etag!=null) {
$httpheader["If-Match"]='"'.$etag.'"';
$httpheader["If-None-Match"]='"'.$etag.'"';
}
$client=new \Conect\Request();
$request=$client->get($url, array("headers"=>$httpheader));
$this->etag="";
if (array_key_exists("ETag", $request->headers_out)) {
$this->etag=$request->headers_out['ETag'];
}
$this->last_request=$request;
$this->etag=str_replace('"', "", $this->etag);
$this->etag=trim($this->etag);
if ($request->code==304) {
throw new ExceptionNoChange("No changes");
}
return $this->response($request->data);
}
“ \ Conect \ Request”部分
if (array_key_exists("headers", $options)) {
$headers_in=array();
foreach ($options['headers'] as $key => $value) {
$headers_in[]=$key.":".$value."";
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_in);
$this->headers_in=$headers_in;
}
操作:我发送了一个带有ETag的请求
期望:Http代码304
结果:带有新ETag的Http 200。