phpdirectorygoogle-drive-apigoogle-drive-realtime-api

Create a folder in google drive php


Is there any way we could create a folder on google drive using PHP? I've been searching all the web for the last 72 hours with no results. What do you think guys? Thanks !


Solution

  • Creating a Folder:

    "In the Drive API, a folder is essentially a file — one identified by the special folder MIME type application/vnd.google-apps.folder. You can create a new folder by inserting a file with this MIME type and a folder title. Do not include an extension when setting a folder title.

    To create a subfolder to a particular folder, specify the the correct ID in the parents property of the file. For example, to create the folder "pets" in an "images" folder whose id value is 0ADK06pfg:"

    POST https://www.googleapis.com/drive/v2/files
    Authorization: Bearer {ACCESS_TOKEN}
    Content-Type: application/json
    ...
    {
      "title": "pets",
      "parents": [{"id":"0ADK06pfg"}]
      "mimeType": "application/vnd.google-apps.folder"
    }
    

    Source: https://developers.google.com/drive/folder

    Examples: https://developers.google.com/drive/examples/php