2017-03-05 88 views
0

我拨打电话获取我的回复和信息,然后打印出来查看一切正常。如何阅读来自YouTube的响应错误v3

$data = file_get_contents([CALL TO API] ); 
$data = json_decode($data, true); 
print("<pre>".print_r($data,true)."</pre>"); 

如果通话很好,我会得到我的结果没有问题。 但在测试时,我需要知道它何时失败以及为什么。

在在线测试演示区域,如果失败,我会得到它。

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "youtube.subscription", 
    "reason": "subscriptionForbidden", 
    "message": "The requester is not allowed to access the requested subscriptions." 
    } 
    ], 
    "code": 403, 
    "message": "The requester is not allowed to access the requested subscriptions." 
} 
} 

但我只得到一个木板页面。
所以我当时决定看我返回头部与

var_dump(headers_list()); 
var_dump(http_response_code()); 

这给了我

array(1) { [0]=> string(23) "X-Powered-By: PHP/5.4.7" } 
int(200) 

正如你看到的,它给了我一个“200” OK头,但仅此而已。 那么,我怎么才能看到YouTube的DEMO页面显示了我?
当我的网站完成时,这也将对以后的错误检查有所帮助。

回答

1
$data = file_get_contents([CALL TO API]); 
print_r($data); // Will print the response HTTP body 
print_r($http_response_header); // Will print the response HTTP headers 
+0

感谢您的快速回复。 “$ http_response_header”给了我 - Array([0] => HTTP/1.0 403 Forbidden [1] => Vary:X-Origin [2] => Content-Type:application/json; charset = UTF- 3] =>日期:Sun,05三月2017 16:18:25 GMT [4] =>到期日:2017年3月5日星期日16:18:25 GMT [5] => Cache-Control:private,max-age = 0 [6] => X-Content-Type-Options:nosniff [7] => X-Frame-Options:SAMEORIGIN [8] => X-XSS-Protection:1; mode = block [9] => GSE [10] => Alt-Svc:quic =“:443”; ma = 2592000; v =“36,35,34”[11] => Accept-Ranges:none [12] => Vary:Origin,Accept - 编码)但是仍然没有YouTube信息被重新调用 – Tempus

+0

好吧,你明显因为某种原因获得了** 403 Forbidden **状态。看看* youtube v3 *文档来找出原因。祝你好运。 –

+0

我知道403代码的原因。我的问题是无法获得错误的API响应。我想要api的可打印响应。但是谢谢你帮我读了一些更好的头文件。附: print_r($ data)仍然没有像以前一样。 – Tempus