I want to withdraw the amount in my account, but the account is not found error. I'm successfully sending sms with the same api.
<?php
$authToken = "myapi";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.clickatell.com/public-client/balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Version: 1",
"Accept: application/json",
"Authorization: Bearer $authToken"
));
echo $result = curl_exec ($ch);
?>
They want like this
curl -X GET --header 'Accept: application/json' --header 'Authorization: Your API key' 'https://platform.clickatell.com/public-client/balance'
Clickatell is not using OAuth2 for authorization, so just remove the "Bearer" from the Authorization. So it should look like this:
<?php
$authToken = "myapi";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://platform.clickatell.com/public-client/balance");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Version: 1",
"Accept: application/json",
"Authorization: $authToken"
));
echo $result = curl_exec ($ch);
?>
Related
How can I transfer this cURL into php? It's not returning anything
Trying all the ways and not working. Do you know a library for codeigniter that not requires composer?
curl --location --request POST 'https://identity.mypayquicker.build/core/connect/token' \\\
--header 'Authorization: Basic {token}'
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=modify'
--data-urlencode 'scope=readonly'",
"language": "curl",
"name": " "
Doing this way
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Basic {token}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://identity.mypayquicker.com/core/connect/token");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, TRUE);
// This option is set to TRUE so that the response
// doesnot get printed and is stored directly in
// the variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'grant_type' => 'client_credentials'
));
$data = curl_exec($ch);
var_dump($data);
Not Returning Anything
Ok so the instructions to connect to this API are:
curl -X GET "https://api.xxxxxxxxxxx.com/jobs?limit=10&offset=0" -H "accept: application/json" -H "X-SmartToken: xxxxxxxxxxxxx"
So my PHP looks like the below but I am getting this [message] => Authentication data missing
$token = "xxxxxxxxxxxxx";
$url = "https://api.xxxxxxx.com/jobs?limit=10&offset=0";
header('Content-Type: application/json');
$ch = curl_init($url);
$authorization = "Authorization: X-SmartToken ".$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
print_r(json_decode($result));
exit;
Anyone see what I am doing wrong?
Thanks
$authorization = "X-SmartToken: ".$token;
The : was missing and the Authorization needed to be removed.
You should not prepend Authorization: to the HTTP header:
$authorization = "X-SmartToken: " . $token;
I want to get the full details of a PayPal transaction by its ID using the PayPal REST API.
I tried to do it as the following:
<?php
include("config.php");
// Reference: https://developer.paypal.com/docs/api/get-an-access-token-curl/
$ch = curl_init("https://api.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json",
"Accept-Language: en_US"
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_USERPWD, $restapp['client_id'] . ':' . $restapp['secret']);
$result = curl_exec($ch);
curl_close($ch);
$access_token = json_decode($result, true)['access_token'];
// Reference: https://developer.paypal.com/docs/checkout/reference/server-integration/get-transaction/#on-the-server
$ch = curl_init("https://api.paypal.com/v2/checkout/orders/<transaction_id>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Accept: application/json",
"Authorization: Bearer " . $access_token
));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
But this always returns error INVALID_RESOURCE_ID. Please note that I am using the client ID and client secret of my live application, and the transaction ID that I use is a live transaction ID too.
After doing some searches, I've found that https://api.paypal.com/v1/payments/orders/<transaction_id> works instead of https://api.paypal.com/v2/checkout/orders/<transaction_id> .. but v1 doesn't return as much information as v2
What am I doing wrong on the v2 endpoint?
Kind regards.
I am trying to add a track to my own playlist with a little php script, but it won't work.
I always get the errror:
{ "error" : { "status" : 400, "message" : "Error parsing JSON." } }
This is the spotify document for adding tracks:
https://developer.spotify.com/web-api/add-tracks-to-playlist/
Has anybody an idea what the problem could be?
$token='my Access token';
$headers = array(
"Accept: application/json",
"Authorization: Bearer " . $token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.spotify.com/v1/users/*myusername*/playlists/*myplaylistID*/tracks' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, 'uris=spotify:track:3DXncPQOG4VBw3QHh3S817' );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result=curl_exec($ch);
print "$result";
$result = json_decode($result, true);
curl_close($ch);
I solved it finally:
$key='***AccessKey***';
$url = 'https://api.spotify.com/v1/users/USERID/playlists/playlistID/tracks?uris=spotify%3Atrack%3A3DXncPQOG4VBw3QHh3S817';
$headers = array(
"Content-Length: 0",
"Accept-Encoding: gzip, deflate, compress",
"User-Agent: runscope/0.1",
"Content-Type: application/json",
"Authorization: Bearer ".$key);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($response);
Try this:
$data = array('uris' => 'spotify:track:3DXncPQOG4VBw3QHh3S817');
$data_json = json_encode($data);
// ...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.spotify.com/...');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array
(
'Content-Type: application/json',
'Content-Length: '.strlen($data_json),
'Authorization: Bearer '.$token
));
$result = curl_exec($ch);
// ...
Im trying to get curl -X GET --header "Accept: application/json" --header "authorization: Bearer <API token>" "https://api.clashofclans.com/v1/clans?name=%23P8PQ8VL2"in php
so far i came up with this
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clashofclans.com/v1/clans?name=%23P8PQ8VL2");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'authorization: Api key'
));
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result, true));
this is the 1st time im using curl in php, thanks in advance :)
Hey thank you all i got it work. i had to use
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Your are overwriting the header with the second set of the options. I would build up the header array like so:
$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "authorization: Bearer " . $yourAPItoken;
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
And send the array:
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);