Search the Community
Showing results for tags 'curl'.
-
Hey Guys, I'm just starting to learn Curl so that I connect to an API. At the moment I have this php code: <?php //******************************************************************************// // // //THIS FILE TAKES A CURRENT JOB AND ADDS IT TO A PAL LABEL PROJECT // // // //******************************************************************************// // ******* TURN ON ERROR REPORTING *****// error_reporting(E_ALL); ini_set('display_errors', '1'); //**** SET THE HEADERS UP FOR AUTHENTICATION *****// $headers = array(); $headers[] = "X-SUBDOMAIN:XXXXXXXXXXX"; // Set the sub domain $headers[] = "X-AUTH-TOKEN:XXXXXXXXXX"; // Set the API Code $headers[] = "application/json"; $total = 50; // this is the max number of pages we will search. with 100 items on a page, and 100 items that means we can return 10,000 items $curl = curl_init(); //**** WE GET ALL OF THE ITEMS CURRENTLY IN THE CURRENT PROJECT AND PUT THEIR UNIQUE ID INTO THE ASSETS ARRAY ***// curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_URL, 'https://api.current-rms.com/api/v1/products?page=1&per_page=100'); // allows up to 1 million products curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // Send the request & save response to $resp $resp = curl_exec($curl); // Convert the response to an array $obj = json_decode($resp, true); // The Obj array currently contains every item in the DB and loads of useless info. We need to extract just the ID and the Name! If I print_r the $obj variable it returns this: I have cut the output down a bit, each item in the products array is about 50 lines long, The only information I actually need to recall is the first two lines which is [id] and the [name]. Is there a simple way that I can do this? So far I have tried to do a Foreach loop and create a new array, but this take a very long time (there are about 600 records!) there must be a much simpler way, where I can unset everything that I don't need, or only call the information that I need from the API? Here is the foreach loop that I used: foreach ($obj as $key) { foreach ($key as $id => $value) { if (!empty($value['name'])) { $products[] = array('Name'=>$value['name'], 'ID' => $value['id'] ); } } } **EDIT ** Once I have my array of ID's (which will be around 600 values long) I then need to get a list of serial numbers that are linked to these id's (there could be up to 100 per id) which will leave me with an array that will be huge! So far I have been getting gateway 504 error's, which I'm hoping is just due to the fact that I'm currently pulling out so much more information than I actually need, so I'm trying to make this more efficient and slim lined. I'm fairly new to PHP, and just do it as a hobby, so go easy on me please! Thanks AJLX
-
I have never used cURL before and have hit a roadblock in my learning. I am trying to make a HTTP GET request to my Wowza server which uses the Rest API to return JSON results. I have authentication set to none on the server at the moment until I can get the script working. I have tested the code below with an external website and it works but, when I try to use it with the URL from the server with the Rest API it just times out. I can make the request in a browser fine, just not from the code. What am I missing or not doing correctly? $ch = curl_init("http://IP_TO_SERVER:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/incomingstreams/ncopeland"); // such as http://example.com/example.xml curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); print $data; The response should be this. { "serverName": "_defaultServer_", "sourceIp": "ncopeland", "isPTZEnabled": false, "applicationInstance": "_definst_", "name": "ncopeland", "isRecordingSet": false, "isStreamManagerStream": true, "isPublishedToVOD": false, "isConnected": true, "ptzPollingInterval": 2000 } -Thanks!
-
Hi, I have a PHP script using the cURL function. This script send the data by a web service. It works often without problem. Sometimes, he sent a double data : same data by two times. I checked the log file this script (by curl_getinfo) on "total_time" When this script works correctly (it send the data only one time) : the total_time is less than 6 second. but when the total_time is more than 7 second, (this is a casual/occasional situation), my script send same data by two times so it is double data! So the web service send the ACK(Acknowledgment) which takes a long time (more than 7 second) and then, the TCP send again same data to a web service. How can I avoid this doubling ? By increasing this time waiting / time limit ? How can I define this time limit for 12 second? Could you help me : Thanks
-
Hi guys, I wanted to make a script login to the website Marktplaats.nl, but it doesn't seem to work.. At the moment I can't post the code as it's on my laptop. Does anyone know how to login and maybe do other stuff on Marktplaats.nl with cURL? Kind regards, Kevin Ruhl.
-
Hello everybody I;m trying to post data to my facbook page (not on my profile wall) but whenever i try it keeps getting posted in my fan page but in different place . I want to post it using My Page name i the wall but it is getting posted in this section (in the left panel of my page..) I want to show in the page wall like all the posts is showing... Here is the script that i've used $touid = "xxxxxxxxxxxxxxxxx"; // This is the page id i'm using $token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // my access token of that page $msg = "Hello again"; $title = "TItle"; $uri = "http://www.google.com"; $desc = "description"; $pic = "http://i.imgur.com/JCdGh.png"; $action_name = "Google"; $action_link = "http://www.google.com"; echo FB_wallpost_wosdk($touid, $token, $msg, $title, $uri, $desc, $pic, $action_name, $action_link); function FB_wallpost_wosdk($touid, $token, $msg, $title, $uri, $desc, $pic, $action_name, $action_link){ if ( ($touid !="") && ($token !="") && ($msg != "") && ($title != "") && ($uri != "") && ($desc != "") && ($pic != "") && ($action_name != "") && ($action_link != "") ) { $url = "https://graph.facebook.com/".$touid."/feed"; $attachment = array( 'access_token' => $token, 'message' => $msg, 'name' => $title, 'link' => $uri, 'description' => $desc, 'picture'=>$pic, 'actions' => json_encode(array('name' => $action_name,'link' => $action_link)) ); // set the target url $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output $result = curl_exec($ch); curl_close ($ch); return $result; } else { return 0; } } My Access tokens have this scopes.. Whenever i post anything it getting posted as a visitors post in my fan page.... Pleas help guys... THank in advance....
-
Hi, I'm using the following code to grab a csv file from one website & keep it on my website. The code is working fine. <?php $url = 'http://thewebsite.com/export.aspx?type=csv&report=nameofthereport~8~'; $path = '/home/path/to/mywebsite.com/public_ftp/incoming/nameofthereport_Area_8.csv'; $fp = fopen($path, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp); ?> Here's what I want to do next. I want to query a database, and replace nameofthereport and 8 with the results of the query. My code to query the database is below. <?php include("/home/path/to/mywebsite.com/public_html/db_connect.php"); //connect to the database $today = date('Y-m-d'); $query1=("SELECT * FROM `table_name` WHERE expiry > $today"); $result1=mysqli_query($GLOBALS["___mysqli_ston"], $query1); $num1=mysqli_num_rows($result1); if ($num1 > 0) { while ($data = mysqli_fetch_array($result1)){ $email_to = $data["email"]; $district = $data["district"]; $report = $data["report"]; } } ?> Based on the code above, I would like to replace nameofthereport with $report and 8 with $district Could you show me the code please? Thanks.
-
I've been puzzling over this for a few days now, and the Siteground L2 support isn't willing to help out here. I'm coding a Wordpress plugin to get affiliate tracking links from Tune/HasOffers. This is totally acceptable behavior AFAIK, and all I have to do is call a URL, and I'll be redirected to a landing page with whatever parm values I've specified. I have a development Linode, where this script works as expected. You can see the output here: http://new.burtlo.info/wp-content/plugins/lmpostback/test.php I've installed that same script on Siteground, but I get a zero length response: http://launchmoxie.com/wp-content/plugins/lmpostback/test.php I've tried a number of variations on making the call, and have tried a number of curl options as well. I'm still stuck. Any suggestions? Thanks in advance. Here's the code: <?php $aff_link = 'http://jump.launchmoxie.com/aff_c?offer_id=26&aff_id=793'; // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $aff_link); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // grab URL and pass it to the browser $response = curl_exec($ch); print_r ($response); echo 'strlen of response = ' . strlen($response); // close cURL resource, and free up system resources curl_close($ch); ?>
-
I need to send a cURL request containing a file to upload as well as a JSON string. I can get a properly formatted request when sending the JSON, but the file is throwing it off. $curl_file_object = '@'.$tmp_name $postData= array( 'JSON'=> json_encode($jsonParams), $reference => $curl_file_object, ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $target); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data;")); curl_setopt($curl, CURLOPT_POST, true); // enable posting curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); // post data curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // if any redirection after upload $response = curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); debug($info); Am I the first one needing to send file binary data along with a json string to a server at the same time?
-
I have two domains - http://domaina.com, http://domainb.com I'm calling domainb.com's url from domaina.com: file_get_contents('http://domainb.com/a.php'); In http://domainb.com/a.php, I'm trying to creating a session or cookie for domainb.com <?php setcookie("key", "value", time()+3600); session_start(); $_session["key1"] = "value1"; ?> But this code is not working. Please help in solving this issue. Thank you.
- 2 replies
-
- curl
- file_get_contents
-
(and 2 more)
Tagged with: