Google Drive Using REST API

Automatically Managing All Google Drive Files.

techhawa-drive-api-home

The core functionality of Drive apps is to download and upload files in Google Drive. However, the Drive platform provides a lot more than just storage. This page describes some of that functionality and points you to resources for building it into your app.

Drive automatically indexes the content of most common file types (e.g. .html, .xml, .txt, ...) for search as soon as they are uploaded. Also, Drive uses OCR to find text in images or PDF files and automated object recognition technology to examine and index identifiable objects, people and places. For other resources such as drawings or other unique file types that are not automatically indexed by Google, apps can provide their own indexable text when they save files to Drive

  • Import, export and format Sheets data.
  • Build and edit charts embedded in a sheet.
  • Control conditional formatting.
  • Create and update named and protected ranges.
  • Add and adjust filtered views.

#1.Getting started with the API

Before you calling the API, you need to set it up.

Read: How To Get Access Token Using REST API ?

Now copy and paste the below code on your local or online server.

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://www.googleapis.com/drive/v2/files",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer client-id",
    "cache-control: no-cache",
    "orderby: folder",
    
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>

#2.Calling Google Drive API Request

Now replace client-id with your value that your are created from here in the above code.

After replacing the values run the file and you will get all the drive files as shown below.

You can cross check by open Google Docs.

techhawa-google-all-drive-links

Live Demo