I have a video file on a server that I would like to send via clickatell's whatsapp API, but I keep getting this error:
[statusCode] => 23
[status] => DELIVERY_FAILURE
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://platform.clickatell.com/v1/message');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"messages\": [{ \"channel\": \"whatsapp\", \"to\": \"27607876384\", \"media\": {
\"fileId\": \"dcd97e173a484ed4bf3f22953103509a.mp4\",
\"caption\": \"First Image File\"}}]}");
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Accept: application/json';
$headers[] = 'Authorization: 9-QxGt35SM-CMm-060G5tA==';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
echo $result;
}
curl_close($ch);
It would be great to do this inline, if possible.
Related
Hi so I'm trying to get a list of all the folders I have on a specific drive. It is working when I do tests on google's api explorer here https://developers.google.com/drive/api/v3/reference/files/list but for some reason when I convert it into a php curl call It doesn't fetch any files
Here's my php curl code.
$ch = curl_init();
curl_setopt($ch, CURLOPT_REFERER, 'referer here i removed it');
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/drive/v3/files?corpora=allDrives&includeItemsFromAllDrives=true&includeTeamDriveItems=true&q=%27'.$folder_id.'%27%20in%20parents%20and%20mimeType%3D%27application%2Fvnd.google-apps.folder%27&supportsAllDrives=true&key'.$_api_key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authorization: Bearer '.$_access_token;
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo "<pre>";
var_dump(json_decode($result, true));
echo "</pre>";
I'm making code to run curl, but when I try to convert the code into a function on php, the code doesn't work.
I run the code in php xampp / cmd shell, PHP version 7, and I have also tried hosting, but the results are the same. I have tried adding data types like those found at https://www.w3schools.com/php/php_functions.asp, but it has no effect.
This is code without being included in the function:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://i.instagram.com/api/v1/friendships/create/2878405206/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "signed_body=cdb3985eb8de0d7ab8bf9a2282615e27452b3f71c30cc95d1b1a325d9f2e36d2.%7B%22_csrftoken%22%3A%221W9jdoDp4GkJRNvWwnZ9Mm1G5Tfh2ub1%22%2C%22user_id%22%3A%222878405206%22%2C%22radio_type%22%3A%22wifi-none%22%2C%22_uid%22%3A%2221423938509%22%2C%22device_id%22%3A%22android-0aaa681cf6d47fdb%22%2C%22_uuid%22%3A%22825ebac9-3235-4cad-b187-7ed685a06b37%22%7D&ig_sig_key_version=4");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'X-Ig-Connection-Type: WIFI';
$headers[] = 'User-Agent: Instagram 24.0.0.12.201 Android (4.4.4/19; 240dpi; 800x480; GT-I9060I; samsung; samsung; grandneove3g; in_ID)';
$headers[] = 'Accept-Language: id-ID, en-US';
$headers[] = 'Host: i.instagram.com';
$headers[] = 'X-Fb-Http-Engine: Liger';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resultLast = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
print_r($resultLast);
and this is the code that has been used as a function:
function sendData($path,$dataHook){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataHook);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'X-Ig-Connection-Type: WIFI';
$headers[] = 'User-Agent: Instagram 24.0.0.12.201 Android (4.4.4/19; 240dpi; 800x480; GT-I9060I; samsung; samsung; grandneove3g; in_ID)';
$headers[] = 'Accept-Language: id-ID, en-US';
$headers[] = 'Host: i.instagram.com';
$headers[] = 'X-Fb-Http-Engine: Liger';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resultLast = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $resultLast;
}
print_r(sendData('https://i.instagram.com/api/v1/friendships/create/2878405206','signed_body=cdb3985eb8de0d7ab8bf9a2282615e27452b3f71c30cc95d1b1a325d9f2e36d2.%7B%22_csrftoken%22%3A%221W9jdoDp4GkJRNvWwnZ9Mm1G5Tfh2ub1%22%2C%22user_id%22%3A%222878405206%22%2C%22radio_type%22%3A%22wifi-none%22%2C%22_uid%22%3A%2221423938509%22%2C%22device_id%22%3A%22android-0aaa681cf6d47fdb%22%2C%22_uuid%22%3A%22825ebac9-3235-4cad-b187-7ed685a06b37%22%7D&ig_sig_key_version=4'));
it should produce {"message": "login_required", "error_title": "You have logged out", "error_body": "Please log in again.", "logout_reason": 2, "status": "fail"}, but the function does not issue anything.
You forgot to add "/" at the end of the url
function sendData($path,$dataHook){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataHook);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'X-Ig-Connection-Type: WIFI';
$headers[] = 'User-Agent: Instagram 24.0.0.12.201 Android (4.4.4/19; 240dpi; 800x480; GT-I9060I; samsung; samsung; grandneove3g; in_ID)';
$headers[] = 'Accept-Language: id-ID, en-US';
$headers[] = 'Host: i.instagram.com';
$headers[] = 'X-Fb-Http-Engine: Liger';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resultLast = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $resultLast;
}
print_r(sendData('https://i.instagram.com/api/v1/friendships/create/2878405206/','signed_body=cdb3985eb8de0d7ab8bf9a2282615e27452b3f71c30cc95d1b1a325d9f2e36d2.%7B%22_csrftoken%22%3A%221W9jdoDp4GkJRNvWwnZ9Mm1G5Tfh2ub1%22%2C%22user_id%22%3A%222878405206%22%2C%22radio_type%22%3A%22wifi-none%22%2C%22_uid%22%3A%2221423938509%22%2C%22device_id%22%3A%22android-0aaa681cf6d47fdb%22%2C%22_uuid%22%3A%22825ebac9-3235-4cad-b187-7ed685a06b37%22%7D&ig_sig_key_version=4'));
I am sending curl request like
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.example.com/Search');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"apikey\": \"xxxxxxxxxxxxxxx\",\"min\": 20, \"items_per_page\": 5000 }");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';
$headers[] = 'X-Requested-With: XMLHttpRequest';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
Now, when "items_per_page" parameter is set to under 4000 it works well everytime, but when its default 5000 it returns empty response.
I tryed to find the error, but its doesn't return anything
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_getinfo returns http_code 504.
I also tryed adding:
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10000 );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
etc. but still can't make it work.
I'm trying to send a request to the RingCentral API to trigger an SMS message to be sent. I've read the documentation and it appears as though I'm posting all of the data in the correct format but I'm getting an error of "Unsupported Media Type".
Does anyone see anything wrong with my code, or is do any of you guys have experience with this API?
$data = array("from" => "+10000000000", "to" => "+100000000", "text" => "test_sms_message");
$data_string = json_encode($data);
$ch = curl_init('https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/sms');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "Authorization: Bearer ".$auth_token;
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
print_r($result);
So I'm going to post an answer to my own question and include the entire code I used. This code will allow you to get an authorization token first and then use that token to send a request to the RingCentral REST API. I couldn't find a working PHP example anywhere online so I'm sure this will help someone else out there.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.devtest.ringcentral.com/restapi/oauth/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=+1XXXXXXXXX&password=XXXXXXXXX&extension=XXX&grant_type=password");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "XXXXXXXXXXXX" . ":" . "XXXXXXXXXXXXXXXXX");
$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$decoded_results = json_decode($result, true);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
echo '<pre>';
print_r($result);
curl_close ($ch);
$auth_token = $decoded_results['access_token'];
// LINE BREAK
$data_string = '{"to": [{"phoneNumber": "+INSERTNUMBER"}],"from": {"phoneNumber": "+INSERTNUMBER}"},"text": "Test SMS message from Platform server"}';
$ch = curl_init('https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/sms');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "Authorization: Bearer ".$auth_token;
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
print_r($result);
i would like to make a CURL to get an auth tokken.
The platform dev forum give me that:
curl -X POST \
--header 'Content-Type: application/json; charset=utf-8' \
--header 'Accept: application/json' \
-d '{"email":"MY_EMAIL","password":"MY_PASSWORD"}' \
'https://api.voluum.com/auth/session'
How do i make that work in PHP?
Try this: https://incarnate.github.io/curl-to-php/
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.voluum.com/auth/session");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"email\":\"MY_EMAIL\",\"password\":\"MY_PASSWORD\"}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json; charset=utf-8";
$headers[] = "Accept: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$vars = '{"email":"MY_EMAIL","password":"MY_PASSWORD"}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.voluum.com/auth/session");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = ['Content-Type: application/json; charset=utf-8',
'Accept: application/json'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
exit;
}
curl_close ($ch);
print_r($server_output);
You can do it like below:-
<?php
$data_string = '{"email":"MY_EMAIL","password":"MY_PASSWORD"}';
$ch = curl_init('https://api.voluum.com/auth/session');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Accept: application/json'
));
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
exit;
}
curl_close ($ch);
var_dump($result);
I run it and found below response (because i don't have mail-id and password):- https://prnt.sc/gdz82r
But the pleasant part is code executed successfully and when you will provide right credentials then it will give you correct output.