I want to write a function that I can upload, download, and delete files from my google drive by using curl in php. Therefore, I'll have to get the access token before uploading any files. The trouble I'm facing is that I got my refresh token, and I did enabled my gdrive api, but I don't know what should by CURLOPT_URL, CURLOPT_POSTFIELDS, and CURL_HTTPHEADER be. The code below showed what I'm trying to do:
<?php
$post = array("grant_type" => "refresh_token",
"client_id" => "MYCLIENT",
"client_secret" => "MYCLIENTSECRET",
"refresh_token" => "MYREFRESHTOKEN",
"Content-length" => "163");
$header = array("Content-type" => "application/x-www-form-urlencoded",
"Content-length" => "163");
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "www.googleapis.com/oauth2/v4/token");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POST, $post);
$output = curl_exec($curl);
curl_close($curl);
print $output;
?>
It keeps telling me "411. That’s an error. POST requests require a Content-length header. That’s all we know." However, I already put content length in both post field and header so I assume the problem might be something else.