I am integrating Truecaller mobile web SDK in my CodeIgniter application for verification. I am successfully invoking the true caller for verification, but I am not getting the response at the endpoints. It is mentioned in the document that they post the response in a few milliseconds, but I am accessing that with the $_POST variable. Is it correct? Can anyone guide me in this, please?
if (isset($_POST["requestId"]) != 'null') {
$endpoints = $_POST["endpoint"];
log_message('error', $_POST["requestId"]);
$url = $endpoint;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$access_token = "Bearer ".$_POST["accessToken"];
$headers = array(
"Authorization: $access_token",
"Cache-Control: no-cache",
"Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
}
Related
foreach ($inventories['rgDescriptions'] as $key => $description){
$samik = $description['app_data'];
$url[] = "https://api2.prices.tf/prices/".$samik["def_index"]."%3B".$samik["quality"];
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"accept: application/json",
"Authorization: Bearer " .$value. " ",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
how can i run this code without having curl_init() expects parameter 1 to be string, array given
If you work with a framework, you better use a queue system. And while you're at it, a good framework can also do the heavy lifting of curl for you... If you don't have a good framework, Laravel might be a good start.
I am using the below code to initiate a GET request but I get only "status":403 from the JSON. The JSON needs a cookie to access. So I added the cookie. What mistake am I making here? Why do I get 403 status and can't access JSON?
$url = "URL HERE";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Cookie: ci_session=COOKIE HERE",
"Accept: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
I want to make a simple call to an API from PHP. It's working fine directly in CURL but not in PHP 7.3.
My real token was replace by TOKEN
CURL:
curl -X POST -H 'Authorization: Bearer TOKEN' -H "Content-Type: application/json" --data-binary '{"query":"{cameraList{name}}"}' https://cloud.camstreamer.com/api/graphql.php
PHP:
<?php
$url = "https://cloud.camstreamer.com/api/graphql.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);;
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers["Authorization"] = "Bearer TOKEN";
$headers["Content-Type"] = "application/json";
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = '{"query": "{cameraList{name}}"}';
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
exit;
You can use
$info = curl_getinfo($ch);
$error = curl_error($ch);
to see what happened.
The content type was not sent correctly.
I changed this:
$headers = array();
$headers["Authorization"] = 'Bearer TOKEN';
$headers["Content-Type"] = "application/json";
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
To this:
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer TOKEN'
));
I'm trying to make a POST request using curl in php and am getting curl error #55. Have been looking around and don't see much information on this error. I don't think my request is formed wrong.
$curl = curl_init();
$encoded = base64_encode("12345:12345");
curl_setopt($curl, CURLOPT_URL, "https://accounts.spotify.com/api/token");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json\r\n",
"Accept: application/json",
'Authorization: Basic ' . $encoded,
"Accept: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
"grant_type" => "refresh_token",
"refresh_token" => 'CxRmNSepUaA41Zs8xIN68fC2wYbRrsrQWKE9547fF6Q12LDOpr551xb95K62+EqnGq6glEHXF4R3qgtgCnOVpr9wFAaxta5/iBKzYBqk+2B442qgiUQu7GyAm+mD1ick3vGrdlZgEEpr/U9EcVVGqXf3XN1EhlZa/vYGgO2opkKedFgbN53Hdd+xQ=='
));
$server_output = curl_exec($curl);
$err = curl_errno($curl);
print("CURL error: ");
print($err);
print($server_output);
I am trying to post a bunch of domains to the godaddy api in order to get information about pricing and availability. However, whenever I try to use curl to execute this request, I am returned nothing. I double checked my key credentials and everything seems to be right on that end. I'm pretty confident the issue is in formatting the postfield, I just don't know how to do that... Thank you to whoever can help in advance!
$header = array(
'Authorization: sso-key ...'
);
$wordsArray = ['hello.com', "cheese.com", "bytheway.com"];
$url = "https://api.godaddy.com/v1/domains/available?checkType=FAST";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_POST, true); //Can be post, put, delete, etc.
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $wordsArray);
$result = curl_exec($ch);
$dn = json_decode($result, true);
print_r($dn);
There are two problems in your code:
Media type of sent data must be application/json (by default this is application/x-www-form-urlencoded), and your PHP app must accept application/json as well:
$headers = array(
"Authorization: sso-key --your-api-key--",
"Content-Type: application/json",
"Accept: application/json"
);
Post fields must be specified as JSON. To achieve this, use the json_encode function:
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($wordsArray));
Full PHP code is:
$headers = array(
"Authorization: sso-key --your-api-key--",
"Content-Type: application/json", // POST as JSON
"Accept: application/json" // Accept response as JSON
);
$wordsArray = ["hello.com", "cheese.com", "bytheway.com"];
$url = "https://api.godaddy.com/v1/domains/available?checkType=FAST";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($wordsArray));
$result = curl_exec($ch);
$dn = json_decode($result, true);
print_r($dn);