PHPackages                             koyabu/googledriveapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. koyabu/googledriveapi

ActiveLibrary[API Development](/categories/api)

koyabu/googledriveapi
=====================

Google Drive API Client

081PHP

Since Dec 29Pushed 4mo agoCompare

[ Source](https://github.com/stievenk/GoogleDriveAPI)[ Packagist](https://packagist.org/packages/koyabu/googledriveapi)[ RSS](/packages/koyabu-googledriveapi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (1)

GoogleDriveClient PHP Library
=============================

[](#googledriveclient-php-library)

Library PHP sederhana untuk berinteraksi dengan **Google Drive API v3**, mendukung:

- OAuth2 Authorization Code Flow
- Refresh Access Token otomatis
- Membuat folder
- Upload file kecil (multipart)
- Upload file besar (resumable / chunked)
- Download file
- Mendapatkan metadata file lengkap
- Membuat dan menghapus share link (permissions)
- Mendapatkan URL file siap pakai di `` atau ``
- Penanganan error terpusat
- Kompatibel dan siap dipublish via **Composer**

---

📦 Instalasi
-----------

[](#-instalasi)

Instalasi melalui composer:

```
composer require koyabu/googledriveapi
```

---

🔧 Konfigurasi Google Drive App
------------------------------

[](#-konfigurasi-google-drive-app)

1. Buka
2. Buat project baru
3. Aktifkan **Google Drive API**
4. Buat OAuth 2.0 Client ID
5. Atur Redirect URI, contoh: ```
    https://example.com/drive/callback

    ```
6. Catat **Client ID** dan **Client Secret**

---

🚀 Cara Menggunakan
------------------

[](#-cara-menggunakan)

### 1. Inisialisasi Class

[](#1-inisialisasi-class)

```
use Koyabu\GoogleDriveApi\GoogleDriveClient;

$drive = new GoogleDriveClient([
    'client_id'     => 'YOUR_CLIENT_ID',
    'client_secret' => 'YOUR_CLIENT_SECRET',
    'redirect_uri'  => 'https://example.com/drive/callback',
]);
```

---

### 2. Mendapatkan Authorization URL

[](#2-mendapatkan-authorization-url)

```
echo $drive->getAuthUrl();
```

User akan login dan mendapatkan **authorization code**.

### 3. Tukar Authorization Code menjadi Token

[](#3-tukar-authorization-code-menjadi-token)

```
$token = $drive->fetchAccessToken($_GET['code']);
// Simpan access token & refresh token
```

### 4. Membuat Folder

[](#4-membuat-folder)

```
$result = $drive->createFolder('Backup');
if (!$result) {
    echo $drive->lastError;
}
```

### 5. Upload File Kecil (&lt;10 MB)

[](#5-upload-file-kecil-10-mb)

```
$drive->uploadFile(__DIR__.'/file.txt', 'file.txt', $folderId); // folderId optional
```

### 6. Upload File Besar (&gt;10 MB)

[](#6-upload-file-besar-10-mb)

```
$drive->uploadLargeFile(__DIR__.'/video.mp4', 'video.mp4', $folderId); // folderId optional
```

### 7. Download File

[](#7-download-file)

```
$drive->downloadFile($fileId, __DIR__.'/downloaded_video.mp4');
```

### 8. Get File Metadata

[](#8-get-file-metadata)

```
$info = $drive->fileInfo($fileId);
print_r($info);
```

- Termasuk `webViewLink` dan `webContentLink` siap pakai untuk `` atau ``

### 9. Get Public URL untuk Web Embedding

[](#9-get-public-url-untuk-web-embedding)

```
$publicUrl = $drive->getFileUrl($fileId, 'content'); // 'view' atau 'content'
```

- `'view'` → webViewLink (preview)
- `'content'` → webContentLink (raw download, bisa langsung di `` atau ``)

Contoh penggunaan di `` atau ``:

```
echo '';
```

```
echo '';
```

### 10. Create / Remove Share Link (Permissions)

[](#10-create--remove-share-link-permissions)

```
$permission = $drive->createShareLink($fileId, 'reader', 'anyone');
$drive->removeShareLink($fileId, $permissionId);
```

---

📝 Catatan Penting
-----------------

[](#-catatan-penting)

- Pastikan timezone dan server clock sinkron.
- Refresh token harus disimpan secara permanen (database/file).
- Access token bisa berubah setelah refresh.
- Untuk file besar, gunakan `webContentLink` langsung di `` tag untuk streaming.
- `fileInfoRaw()` hanya untuk file kecil (&lt;2MB) agar aman untuk memori.
- `getFileUrl()` helper memudahkan embed file di web.

---

🧩 Struktur Direktori Disarankan
-------------------------------

[](#-struktur-direktori-disarankan)

```
/
│── src/
│   └── GoogleDriveClient.php
│── composer.json
│── README.md
│── LICENSE

```

---

🧪 composer.json Contoh
----------------------

[](#-composerjson-contoh)

```
{
  "name": "koyabu/googledriveapi",
  "description": "Google Drive API Client",
  "type": "library",
  "license": "MIT",
  "autoload": {
    "psr-4": {
      "Koyabu\\Googledriveapi\\": "src/"
    }
  },
  "authors": [
    {
      "name": "Stieven Kalengkian",
      "email": "stieven.kalengkian@gmail.com"
    }
  ],
  "minimum-stability": "dev",
  "require": {
    "google/apiclient": "^2.0"
  }
}
```

---

🤝 Kontribusi
------------

[](#-kontribusi)

Pull request, bug report, dan perbaikan sangat diterima.

---

📄 Lisensi
---------

[](#-lisensi)

MIT License atau sesuai kebutuhan Anda.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance52

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/09b7ee9510aae1fe1a8aea5c2f2c39683d3c3f20d389420e6f862b322aed8eee?d=identicon)[stievenk](/maintainers/stievenk)

---

Top Contributors

[![stievenk](https://avatars.githubusercontent.com/u/486428?v=4)](https://github.com/stievenk "stievenk (5 commits)")

### Embed Badge

![Health badge](/badges/koyabu-googledriveapi/health.svg)

```
[![Health](https://phpackages.com/badges/koyabu-googledriveapi/health.svg)](https://phpackages.com/packages/koyabu-googledriveapi)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M478](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M271](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
