【发布时间】:2017-05-21 13:40:41
【问题描述】:
所以我这几天一直在想办法解决这个问题,但到目前为止还没有……
这是我的问题:我正在尝试从 SendGrid GET API 检索 json 对象。 -> https://api.sendgrid.com/v3/suppression/bounces/
这需要 cURL 身份验证,正如支持人员告诉我的那样:
curl --request GET \
--url https://api.sendgrid.com/v3/suppression/bounces/
--header 'authorization: Bearer YOUR_API_KEY'
--header 'Content-Type: application/json'
因此,由于我对 cURL 还很陌生,因此无法通过以下方式检索数据:
$ch = curl_init('https://api.sendgrid.com/v3/suppression/bounces/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , 'authorization: Bearer MY_API_KEY'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$bounces = json_decode(file_get_contents($response),true);
我得到这个错误:
Warning: file_get_contents({"errors":[{"field":null,"message":"resource not found"}]}): failed to open stream: No such file or directory in ...
谢谢! :)
【问题讨论】:
-
你试过了吗:
$bounces = json_decode($response, true);? -
我终于熬过去了,谢谢