Edits history of script submission #23032 for ' Get File Metadata (gdrive)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get File Metadata
     * Get a file's or folder's metadata (name, mime type, parents, owners, size, links, …). Use `fields` to narrow the response; the default `*` returns every field.
     */
    export async function main(
      auth: RT.Gdrive,
      file_id: string,
      fields: string = "*"
    ) {
      const url = new URL(`https://www.googleapis.com/drive/v3/files/${file_id}`)
      url.searchParams.append("fields", fields)
      url.searchParams.append("supportsAllDrives", "true")
    
      const response = await fetch(url, {
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 1 hour ago