问题
I send a "playlistItems" request with this headers:
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""
}
The url is: https://www.googleapis.com/youtube/v3/playlistItems?part=id%2Csnippet&playlistId=UUvmF_tzu-eK6FRfMlOp6-Fg
But i receive a ETag diferent without the content change.
Youtube V3 really support ETag? or headers are wrong?
I do not use any oficial library. My code uses PHP and Curl.
$this->execute(
"playlistItems",
array("part"=>"id,snippet","playlistId"=>$channelId)
,$etag
);
And
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);
}
Section of "\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;
}
Action: I sent a request with a ETag
Expect: Http code 304
Result: Http 200 with a new ETag.
来源:https://stackoverflow.com/questions/56890916/youtube-api-v3-etag-support-fail-content-not-change-but-etag-change