我正在运行一个页面,以收集登录用户通过Eventbrite API创建的事件。
第一个CURL请求返回一个正确的响应,并回显org_id给出正确的响应,但是对于第二个curl请求,响应和err均为空,并且error_log中没有错误,我在邮递员和返回正确的响应。
(session_init.php仅包含<?php session_start()?>
)
<?php
include 'session_init.php';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.eventbriteapi.com/v3/users/me/organizations/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer ".$_SESSION['token'],
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
echo $response;
//echo $response.organizations.id;
$response=(json_decode($response, true));
//print_r($response);
$org_id = $response['organizations'][0]['id'];
echo $org_id;
if(ISSET($org_id)){
$_SESSION['org_id'] = $org_id;
}
else{
$_SESSION['org_id']=null;
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.eventbriteapi.com/v3/organizations/".$_SESSION['org_id']."/events",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer ".$_SESSION['token'],
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
$response=(json_decode($response, true));
}
?>
编辑:这是$info = curl_getinfo($curl); var_dump($info);
array(26) { ["url"]=> string(66) "https://www.eventbriteapi.com/v3/organizations/299067012672/events" ["content_type"]=> string(24) "text/html; charset=utf-8" ["http_code"]=> int(301) ["header_size"]=> int(1520) ["request_size"]=> int(176) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.42656) ["namelookup_time"]=> float(2.5E-5) ["connect_time"]=> float(0.090498) ["pretransfer_time"]=> float(0.268933) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0.426508) ["redirect_time"]=> float(0) ["redirect_url"]=> string(67) "https://www.eventbriteapi.com/v3/organizations/299067012672/events/" ["primary_ip"]=> string(12) "52.22.172.91" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(13) "46.37.183.253" ["local_port"]=> int(40102) }