I am trying to clear Trash using php and drive api v3. Code excutes with no error but trash in drive is not deleted. Here is my code please help me to fix this. Thanks For your time.
if($_POST['trash']) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash?key='.$token.'");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Authorization: Bearer ' . $token
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
};
I believe your goal and current situation as follows.
You want to use "Files: emptyTrash" in Drive API v3 using curl of php.
Your access token of $token can be used for using this API.
In order to achieve your goal, how about the following modification?
From:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash?key='.$token.'");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Authorization: Bearer ' . $token
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
To:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/drive/v3/files/trash");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Note:
At "Files: emptyTrash", no values are returned.
If $token in your script is the API key which is not the access token, please retrieve the access token and use it. Please be careful this.
Reference:
Files: emptyTrash
Related
I'm using sandbox and i have generated
Key and token
I have my seller sandbox account .
I'm trying to use sell api (inventory and fullfillment ),but its giving as "A resource (URI) associated with the request could not be resolved" with an error code 3003.
This is the git hub package i'm using in my code .
<?php
// Your token
$authToken = 'AgAAAA**AQAAAA**aAAAAA**MJNfXQ**nY+sHZ2PrBmdj6wVnY+sEZbIEFTWmW7eYbvzFw0uXajYBe6j5ddEO3crLb0oCIHHhc3UFOFYX4+mzwE/6HboGAezWiTXbfJvi034ScYcE0MJ08YHjIt3ciNyu/7OHUnbedLVhNqYjGt/oXL/9bvQPHFcGH/+XS1KfNV+XcdZV/2HJ8n+QNhYawC3lIKeKm6rsH1HH3x9ZECNYvGzPTjL23uaTH53UoshKYPFTi/uq7UO4ZNccE/NdreamfAzGiBTAz6pqL+SnFLrOVn9llPNlMGLO/yVEkAFIdwDF2KduXPVV7ZFTVX9ncfdX04r80Jx4LiMIEnhq5Ftjwq48q+arkDy8Y4T+bf6YPE5UICJnXyGAkJJhSZa5hliV+TRgSFRQkBhCVJf+ZAvVO4CA/TRZxtH77YTSj/Z9HGSzDpavFfh+7IM2lmQxCoHmhHI7e8pta6QBMvKOuq65SH17IW0bYog76dFsDa5OjnjFmFMU4u4dzF9lTFm8lw0TTqjnGja8mh5CZA4OBSsVgkqq4diWacZXKQw5p1tofG4aYbQJ8XNnYBPOAyH2fuSlWmY4Lj+RpBbVmhtj5RA/h/MKUmgN+USGdT0DeKWQMCTVmNaQFJbSEQEzdSRBBQhvqubhnqPG4/95gwanPOxasEbQxMUpnWnF4oOE+eS432P9ILTSOnEZ7Qs70R/GcilczhaPUDJUH9+dFp4DMNVT2P1tiflmBAt';
$header = array('Accept: application/json',
'Authorization: Bearer '.$authToken,
'Content-Type: application/json'
);
$placeOrderUrl =
"https://api.sandbox.ebay.com/sell/fulfillment/v2/order/110181400870-
27973775001";
$body = '{}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($placeOrderUrl));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS,$body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
$information = curl_getinfo($ch);
print_r($response);
?>
I needs to pull the orders as in the doc for the rest api .
I don't know where i'm stuck . Thanks in advance if any one can help me out .
I'm creating the authentication and getting an access token fine but the problem arises when I try to send a request. I'm creating the headers using PHP
<?php
define("POST", "POST");
**$environment=' https://api-crt.cert.havail.sabre.com';**
$userId='XXXXXXX';
$domain='AA';
$Group='XXXXXXXXXX';
$formatVersion='V1';
$clientSecret=base64_encode('XXXXXXXXXXX');
$client_id=base64_encode($formatVersion.":".$userId.":".$Group.":".$domain);
$bulid_credential=base64_encode($client_id.":".$clientSecret);
######################## Step 1: Get Token #############################
**$ch =curl_init("https://api-crt.cert.havail.sabre.com/v2/auth/token");**
$vars ="grant_type=client_credentials";
$header =array(
'Authorization: Basic '.$bulid_credential,
'Accept: */*',
'Content-Type: application/x-www-form-urlencoded'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res= curl_exec($ch);
$result=json_decode($res);
$token=$result->access_token;
########################## Step 2: Call the REST API###################
**$url="https://api.test.sabre.com/v3.3.0/shop/flights?mode=live";**
$header = array(
'Authorization: Bearer'. $token,
'Content-Type: application/json'
);
$calltype='POST';
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $calltype);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonrequest);//Request
array_push($header, 'Content-Type: application/json');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result=curl_exec($ch);
$result1=json_decode($result);
curl_close($ch);
?>
The Sabre Response :
{"status":"Incomplete","type":"Application","errorCode":"ERR.2SG.PROVIDER_ERROR","timeStamp":"2017-10-11T06:02:08.658-05:00","message":"Error occurred while invoking service rest:readMetadata:1.13.7.SNAPSHOT"}
1) Did you ensure that $token is a string and not an object?
I use this:
$result=json_decode($res, TRUE);
$token=$result['access_token'];
Instead of this:
$result=json_decode($res);
$token=$result->access_token;
2) Did you ensure that the content of $jsonrequest is valid?
Maybe it's not the PHP code that is incorrect, but your JSON query.
I am in the process of creating a super simple PHP page that sends JSON data to an remote API via POST. I am having issues with it and hoping someone here could help me out.
This is what I have so far
$url = "https://remoteHost.com/api/post";
$json = '{"message":"textHere", "user":"userABC"}';
$ch = curl_init();
$timeout = 0;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic --ACB123-ABC123---ABC123---',
'Content-Type: application/json',
'Content-Length: ' . strlen($json),)
);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
When I execute this nothing happens. The page loads without errors but it looks like the curl isn't actually doing anything. Any Ideas?
I'm trying to make an HTTP Request in PHP using cURL. The Request goes to the Routific (Route Optimization) API -> https://docs.routific.com/v1.3.1/docs
The idea is to send a JSON with different waypoints and get an optimal route back. Unfortunately, I get the following error when executing the code:
{"error":"Missing network"}
My Code looks as follows:
<?php
$data_string = json_encode(file_get_contents('Routes.json'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.routific.com/v1/vrp");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: bearer API_KEY')
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$result = curl_exec($ch);
echo $result;
curl_close($ch);
?>
What is wrong?
Thanks!
So i'm writing a function for a client whom wants a simple function to use on his social site so that users can follow channel on Twitch, no SDKs nothing like that i have the following function:
function twitch_follow_channel($user, $channel, $client_id, $access_token) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_URL, 'https://api.twitch.tv/kraken/users/'.$user.'/follows/channels/'.$channel.'?oauth_token='.$access_token);
$h = 'Client-ID: '.$client_id.', Accept: application/vnd.twitchtv.v3+json, Authorization: OAuth '. $access_token;
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth '.$access_token,
'Client-ID: '.$client_id,
'Content-Length: '.strlen($h),
'Accept: application/vnd.twitchtv.v3+json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
$r = curl_exec($ch);
$ci = curl_getinfo($ch);
r($ci);
r($r);
return json_decode($r, true);
}
i include the Content-length in the HTTP HEADER i don't know what i'm missing
Notes
The access token has user_follows_edit scope.
r() is used instead of var_dump()
I'm already aware of the DOCs at GitHub, followed it carefully
Recently did that myself so how about you add:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
This way you say CURL to use PUT as request.
To unfollow simply replace PUT with DELETE and your gucci.
Atom8tik