w3lifer/php-google-drive 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

w3lifer/php-google-drive

最新稳定版本:1.0.8

Composer 安装命令:

composer require w3lifer/php-google-drive

包简介

PHP Google Drive

README 文档

README

Installation

composer req w3lifer/php-google-drive

Usage

<?php

// require_once __DIR__ . '/vendor/autoload.php';

use w3lifer\Google\Drive;

$googleDrive = new Drive([
    'pathToCredentials' => __DIR__ . '/credentials.json', // Required
    'pathToToken' => __DIR__ . '/token.json', // Required
]);

$fileId = $googleDrive->upload(
    __DIR__ . '/hello.txt',  // Required
    [ // Optional
        '<folder id>',
        '<folder id>',
    ]
);
  • Folder ID: https://drive.google.com/drive/folders/<folder-id>

How to get Google Drive API credentials

Create a new project

Enable Google Drive API

Create credentials

If you left the screen above, go to "Enable API & services" and click "Google Drive API":

Publish app

How to get a token

1. Save the credential to disk and specify the path to them by setting the pathToCredentials configuration key

$googleDrive = new Drive([
    'pathToCredentials' => __DIR__ . '/credentials.json', // Required
    'pathToToken' => __DIR__ . '/token.json', // Required
]);

Note that pathToToken is the path where the Drive saves the token after the first run. That is, the token will be saved automatically along the specified path; it is needed for your application to subsequently access Google Drive without the consent screen.

2. Run your app

  • You will receive the following message in the console:
Open the following link in your browser:
https://accounts.google.com/o/oauth2/v2/auth?...
Enter verification code:
  • Open the link in the message and choose desired account:

  • The warning "Google hasn't verified this app" may appear. Click "Advanced" and then "Go to ... (unsafe)":

  • On the next screen click "Continue":

  • After the redirect, copy the code from the address bar of your browser and paste it in the console:

Open the following link in your browser:
https://accounts.google.com/o/oauth2/v2/auth?...
Enter verification code: <here>

3. Enjoy!

Tests

make tests # make t

统计信息

  • 总下载量: 99
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-17