I want to use the API from opendatacommunities.org
the following code is used for the same. But I a get a "no acceptable resource available" message
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, https://epc.opendatacommunities.org/api/v1/domestic/search?address=liverpool");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0")
$headers = array();
$headers[] = "Accept: text/json";
$headers[] = "Authorization: Basic XXXXXXXXXXXXXXX";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch); }
curl_close ($ch);
Can any one help?
Hi i was able to fix it as the code
$headers[] = "Accept: text/json";
was replaced with
$headers[] = "Accept: application/json";
thank you for the help DhamankarTejas
Related
I want to upload the media via Whatsapp cloud API in order to send the media to WhatsApp, I have followed the link below, but having the stated issue.
https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#get-media-id
Array ( [error] => Array ( [message] => (#100) The parameter messaging_product is required. [type] => OAuthException [code] => 100 [fbtrace_id] => AQPftb9Bf343375gQ_QytxNen ) ) 400
My Code is
// #1640191015925.jpg on my root folder
$post = [
'file' => '#1640191015925.jpg;type=image/jpeg',
'messaging_product' => 'whatsapp'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v13.0/Phone-Number-ID/media');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$YOUR_WHATSAPP_ACCESS_TOKEN = '+++++++';
$headers[] = "Authorization: Bearer $YOUR_WHATSAPP_ACCESS_TOKEN";
$headers[] = "Content-Type: image/jpeg";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = json_decode(curl_exec($ch), true);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//$MEDIA_OBJECT_ID = $result['media'][0]['id']; //MEDIA OBJECT ID
print_r($result);
print_r($httpcode);
?> ```
I had the same issue, after some digging around I wrote this function to upload a file and return the id.
function waFileUploader($token, $file, $senderid){
$mime = mime_content_type($file);
$info = pathinfo($file);
$name = $info['basename'];
$curlfile = new CURLFile($file, $mime, $name);
$filedata = array("messaging_product"=>"whatsapp", "file" => $curlfile);
$url = 'https://graph.facebook.com/v13.0/' . $senderid . '/media';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Authorization: Bearer $token", "Content-Type: multipart/form-data"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $filedata);
$r = curl_exec($ch);
curl_close($ch);
$id = json_decode($r, true);
return $id["id"];
}
I'm trying to convert this curl command into php:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer API_TOKEN" \
-d '{"image": "ubuntu-16.04"}' \
https://api.hetzner.cloud/v1/servers/42/actions/rebuild
Can anyone help please?
You can use this tool to generate PHP-CURL using curl command parameters.
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.hetzner.cloud/v1/servers/42/actions/rebuild');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"image\": \"ubuntu-16.04\"}");
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: _ENV["Bearer API_TOKEN"];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
webhook is set...
I want to send a message to the robot users in response to any message from them
AND
I really want to use cURL
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chat_id = $update['message']['chat']['id'];
echo $chat_id;
$ch = curl_init();
$url = "https://api.telegram.org/bot" . bot_token . "/";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "sendMessage?chat_id=" . $chat_id . "&text=hello");
$res = curl_exec($ch);
curl_close($ch);
sendMessage is URL Path, not POST Body.
URL should be .../bot123:AA/sendMessage.
Basically I need to get the same information that is presented here
http://offer.ebay.com/ws/eBayISAPI.dll?ViewBidsLogin&item=221864583914&rt=nc&_trksid=p2047675.l2564
According to the documentation, GetItemTransactions is the method I'm searching for. I tried that and it gives no transactions.
Here is the code if you'd like to test it yourself(curl should be enabled)
$url = "https://api.ebay.com/ws/api.dll";
$token = "AgAAAA**AQAAAA**aAAAAA**D55JWA**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6ABlIWoAZeApg2dj6x9nY+seQ**23sDAA**AAMAAA**efeUquPbnQ2MiXisn2kcSIvJ3MOhnzuRf7V5BmJdhMLNVX11yxak3P3jIoDV58s7VAFRcYfTnaltMr3CNRBpeVFAKry+t+jTfuXAaKRfUN2z4LjNngQH5/QhJTrDsVTTEinEizj4UXnpNLXWYErZ4sEn9gGcG6jALdKbLam36m9EeBbF9ZDTUivd8MkQYXOAa3MWl3+vau06gbd9Dm3sXiMB46ainm8EvxAm+ZUEGtxCNRHTDdsuMOTzmC0Jc5IYisf2kWMSyjaFG3bruEo1WLAYsSGuixOwLtVEAZkc5MVbSoHtfv9q4HWHv0o0hOgJP/dN7eyYRhC6uclvs+fk4NyyOh3+6hSKYEcyNXdFm+9ZJmZdCieg4PtEmyrmSy2YV5M/Upqq53D9+TSfBHchfGZDCrFw3fY3RHnE1gZKnV3gaOb6lAbhDV79QDkM4Qyi3wfEQE0FzPvzDzUuADy1nEtPSRa2Koz1bR57Lvt5dc/vh0z0JLvyNVEs6wZNfDcj5mwgXvryQMMMBIOAgY/w3gEHiuyw/Z7iIV+y9h4FMHIaroeAaBpHa5JXbojkCph5Ej8KUOesjbUstZXEjBD+XdEDRSK5ThR2/T6+9N5eU1uj+7PuhoHllZhH6AKpo5tDlAzkTfU5YeK7vtV8Mb4ByHNgAA08nizMM1bc35YMmf1LS7D6gV/pNNT2t5cDXsoP6kWtcbsmwIW+XaBj+A2J7a0VxWmXvuDQI3q7+HpLgA1q35Mke5pACVE1OlOvXzOt";
function GetItemTransactions(){
global $url, $token;
$post = '<?xml version="1.0" encoding="utf-8"?>
<GetItemTransactionsRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<ItemID>152343698747</ItemID>
<RequesterCredentials>
<eBayAuthToken>'.$token.'</eBayAuthToken>
</RequesterCredentials>
</GetItemTransactionsRequest>';
$headers = array("X-EBAY-API-COMPATIBILITY-LEVEL: 967",
"X-EBAY-API-CALL-NAME: GetItemTransactions",
"X-EBAY-API-SITEID: 0",
"Content-Type: text/xml");
$result = request($url, $post, $headers);
return json_decode(json_encode(simplexml_load_string($result)), true);
}
function request($url, $post, $headers) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
if($post){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
echo "<pre>";
print_r(GetItemTransactions());
echo "</pre>";
shorte.st is a url shorten service.
recently they changed the api as following:
curl commandline
curl H "public-api-token: fakekey" -X -d "urlToShorten=google.com" PUT http://api.shorte.st/v1/data/url
response:
{"status":"ok","shortenedUrl":"http:\/\/sh.st\/XXXX"}
How to change it into php curl version?
function shst($url){
$apiurl="https://api.shorte.st/v1/data/url";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT' );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('public-api-token: fakekey','X-HTTP-Method-Override: PUT'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "urlToShorten=".$url);
$data = curl_exec($ch);
curl_close($ch);
$obj = json_decode($data);
$ret=$obj->{'shortenedUrl'};
return $ret;
}
The sample they provided used the wrong url. should be https not http
This works:
function shst($url){
$key="";//your key
$curl_url = "https://api.shorte.st/s/".$key."/".$url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curl_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$array = json_decode($result);
$shortest = $array->shortenedUrl;
return $shortest;
}