slingshotdancu Posted December 18, 2017 Share Posted December 18, 2017 (edited) Hello. I'm fairly new to PHP, and unfortunately the specificity of my problem means I have to just ask about it: I am using Eventbrite's API and cURL, pulling data into a table (formatted through DataTables) and I am getting this "Couldn't resolve host" error, for approximately the first 11 pages, at which point I am presented with the data formatted as expected. Here is the result: https://tinyurl.com/yde49f3d Any help is much appreciated, this one has me beat-down and put my junior-level programmer ego in check! And here is the back-end code: https://pastebin.com/pCSkU6UQ Note: function u() and function h() are urlencode() and htmlspecialchars(), respectively. Thanks! Edit: Realized I wouldn't click the link to look at code in another tab, so here's the code directly: <table id="events" class="display compact" width="100%"> <thead> <tr> <th>Event ID</th> <th>Event Name</th> <th>Location</th> <th>Description</th> <th>Link</th> <th>Time</th> <th>Date</th> <th>Add Event</th> <th>View Attendees</th> </tr> </thead> <tbody> <?php $token = "IPUTMYAPITOKENINTOAPUBLICPOSTONTHEINTERNET"; $pageNumber = 0; $continuationToken = ""; $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_URL => "https://www.eventbriteapi.com/v3/users/me/owned_events/?token=IPUTMYAPITOKENINTOAPUBLICPOSTONTHEINTERNET", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET" )); $urlloop = u(h('https://www.eventbriteapi.com/v3/users/me/owned_events/?')); $response = curl_exec($curl); $err = curl_error($curl); if ($err) { echo "cURL Error #:" . $err; } else { // Stores the json response data in an array $array = json_decode($response, true); } ?> <?php for($i = 0; $i < $array["pagination"]["page_count"]; $i++) { if($array["pagination"]["has_more_items"] === true) { for($j = 0; $j < $array["pagination"]["page_size"]; $j++) { $continuationToken = $array["pagination"]["continuation"]; $newurl = '"'; $newurl .= $urlloop; $newurl .= "continuation="; $newurl .= $continuationToken; $newurl .= "&token="; $newurl .= $token; $newurl .= "&page="; $newurl .= $pageNumber; $newurl .= '"'; curl_setopt_array($curl, array(CURLOPT_URL => $newurl, CURLOPT_CUSTOMREQUEST => "GET")); $response = curl_exec($curl); $err = curl_error($curl); if ($err) { echo "cURL Error #:" . $err; } else { $array = json_decode($response, true); } $event_id = $array['events'][$j]['id']; $event_name = $array['events'][$j]['name']['text']; $location = $array['events'][$j]['venue_id']; $description = $array['events'][$j]['description']['text']; $link = $array['events'][$j]['url']; $time = $array['events'][$j]['start']['local']; $date = $array['events'][$j]['start']['local']; ?> <tr><td><?php echo($event_id);?></td> <td><?php echo ($event_name);?></td> <td><?php echo ($location);?></td> <td><?php echo ($description);?></td> <td><?php echo ($link);?></td> <td><?php echo ($time);?></td> <td><?php echo ($date);?></td> <td><a href=<?php echo 'add-events.php?id=' . $event_id . '&name=' . h(u($event_name)) ?>><button class="btn btn-default btn-md">Add Event</button></a></td> <td><a href=<?php echo 'show-attendees.php?id=' . $event_id . '&name=' . h(u($event_name)) ?>><button class="btn btn-default btn-md">View Attendees</button></a></td></tr> <?php } } $pageNumber++; } ?> </tbody> </table> <script> $('#events').dataTable( { "autoWidth": false, "columns": [ { "width": "5%" }, { "width": "10%" }, { "width": "5%" }, { "width": "75%" }, { "width": "5%" }, ] } ); </script> <?php curl_close($curl); ?> <?php include_once('footer.php'); ?> </body> Edited December 18, 2017 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/305935-couldnt-resolve-host-curl/ Share on other sites More sharing options...
slingshotdancu Posted December 18, 2017 Author Share Posted December 18, 2017 A sincere thank you, requinix. Lesson learned. Quote Link to comment https://forums.phpfreaks.com/topic/305935-couldnt-resolve-host-curl/#findComment-1554737 Share on other sites More sharing options...
Solution requinix Posted December 18, 2017 Solution Share Posted December 18, 2017 Ah, I forgot to reply after making that edit Look at what you're doing with the URLs: $newurl = '"'; $newurl .= $urlloop; $newurl .= "continuation="; $newurl .= $continuationToken; $newurl .= "&token="; $newurl .= $token; $newurl .= "&page="; $newurl .= $pageNumber; $newurl .= '"';There are quotes in it. Quotes. That's definitely not valid. I'm also very concerned about how often you're hitting that URL: dozens of times per page. Surely you can move the cURL call out of those loops? Quote Link to comment https://forums.phpfreaks.com/topic/305935-couldnt-resolve-host-curl/#findComment-1554738 Share on other sites More sharing options...
slingshotdancu Posted December 18, 2017 Author Share Posted December 18, 2017 Indeed, I removed the quotes, and immediately hit EventBrite's rate limit. Flawless advice, thanks! Now I suppose I'll be waiting an hour on that rate limit to try again... Quote Link to comment https://forums.phpfreaks.com/topic/305935-couldnt-resolve-host-curl/#findComment-1554740 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.