dongzhonggua4229 2016-02-05 12:43
浏览 58
已采纳

Guzzle 6使用“If-None-Match”标题和etags返回200而不是304

I'm using Guzzle 6 to communicate with the Youtube API.
I've read about the etags in the YoutubeAPI docs and tried to make it work for me.
First, I tested it at the OAuth 2.0 Playground by Google.
After a few tries I had set it up and the result was following:

Google OAuth 2.0 Playground and using ETags

It returned successfully 304 for this particular request.
Now I've used this code to recreate above response.

$this->client->get('https://www.googleapis.com/youtube/v3/playlists?part=id,snippet&id=PLQvsw2H5Quochc6RgdIO-zvTKB012BTz1&key=MyApiKey', [
    'header' => [
        'If-none-match' => "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/FVDC5fyfcQ3KmIbwFIpgNgWJFUo\"",
    ]
]);

But it always returns an response with a 200 code.

200 instead 304 returned

I don't know alot about the HTTP protocol and therefore I'm not sure if I'm missing something..
(either calling with Guzzle or the headers itself)

  • 写回答

1条回答 默认 最新

  • dongtuo7364 2016-02-05 15:37
    关注

    At first glance, it looks like your request is failing the authentication portion of the request, based upon the fact that the copy and pasted image lists authentication yet it is not within your code snippet. It is hard to tell without being able to view the full response received.

    Use auth to enable authentication for the transaction. Use debug to enable debugging, this will allow you to compare the request and responses received by Guzzle with expectations.

    You might also be interested in utilizing the Official Google PHP Client library. At the core this library uses Guzzle.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了