Hey Guys, I am trying to get a query result with CURL but the response is always false. If I try it with my browser, I get a response (successfull query)
Heres what i have:
function curling($method, $params){
$query = http_build_query($params);
$url = $this->api_url . '/' . $this->api_version . '/search/' . $method .'?api_key='.$this->api_key .
'&language='. $this->language . "&" .$query ;
$ch = curl_init();
if ($ch) {
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FAILONERROR => true,
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Content-type: application/json'
) ,
));
if ($this->debug) {
error_log("DEBUG: Calling URL: {$url}");
}
if (!empty($data) && is_array($data)) {
if ($this->debug) {
error_log("DEBUG: POSTDATA: " . var_export($data, true));
}
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$results[] = curl_exec($ch);
$results[] = curl_getinfo($ch);
curl_close($ch);
}
return $results;
}
$return[0] is always "false" A generated API key looks like this: https://api.themoviedb.org/3/search/movie?api_key=5bbc08[......]7f9d8c&language=de-DE&query=Iron+Man This key works in my browser I requested a token for my "application", but the Name of the App is not displayed in my account. I also think that isn't necessary?!
I don't have a V-Server or anything yet, I just want to develop at my local maschine (windows)
Thanks for your help!
找不到电影或节目?登录并创建它吧。
Travis Bell 的回复
于 2017 年 01 月 29 日 11:38上午
Hi @exa.byte
Can you paste the entire response body and response headers? I have a feeling your answer lies there. If I was to guess, you're not constructing the request fully and it's throwing back an invalid API key response (status code 7).
exa.byte 的回复
于 2017 年 01 月 29 日 11:40上午
Hi, WOAH, that was quick. Thank you. Heres the $result array
How do I format just an array corectly? The Function above was formatted automatically :/ sorry for the view
array(2) { [0]=> bool(false) [1]=> array(26) { ["url"]=> string(112) "https://api.themoviedb.org/3/search/movie?api_key=5b[....]f9d8c&language=de-DE&query=Iron+Man" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(1) ["redirect_count"]=> int(0) ["total_time"]=> float(0.235) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0.11) ["pretransfer_time"]=> float(0) ["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) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(14) "54.243.147.233" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(12) "192.168.3.42" ["local_port"]=> int(52262) } }
Thank you so far
Travis Bell 的回复
于 2017 年 01 月 29 日 11:44上午
Heh, unfortunately, that's not that useful. You should still be getting a response as it looks like the request completed. I want to see the response body.
I don't have any experience with PHP, I am just wanting to see the response you are getting back.
exa.byte 的回复
于 2017 年 01 月 29 日 11:55上午
Hi, thanks for your help. The Response-Header would be just "false" I just found out the curl_error was "60" which is an SSL-Error. I changed the URL from https to http and now it works.
Thanks for your suggestion :)
Travis Bell 的回复
于 2017 年 01 月 29 日 11:57上午
Glad you sorted it out!