我尝试将文件上传到Google云端硬盘,但我无法做到。
我尝试使用google-api-php-client
,但此API不稳定,缺少功能......当我按照文档操作时,他们无法工作,因为$client->getAuth()->authenticate(code)
没有退出
现在API正在发生变化。我使用v1-master
。
我尝试使用curl后却出现错误:Error String:Couldn't resolve host 'account.google.com'
。
请有人有解决方案用PHP上传文件到Google云端硬盘吗?
谢谢
答案 0 :(得分:0)
嘿,你可以尝试这个片段.. [致Ben Vicvoz的信用]
/*******************************************************************************
* file: google_drive_upload.php
* author: ben servoz
* description: script to upload files to Google Drive
* notes: instructions at http://ben.akrin.com/?p=2080
*******************************************************************************/
// configuration
// google oauth
$client_id = "your client ID here" ;
$client_secret = "your client secret here" ;
$refresh_token = "your refresh token here" ;
// chunk size (this HAS to be a multiple of 256KB so only change the last integer)
$chunk_size = 256 * 1024 * 400 ; // this will upload files 100MB at a time
// miscellaneous
$verbose = true ;
$file_binary = "/usr/bin/file" ; // used for detecting mime type
// md5
$check_md5_after_upload = true ;
$md5sum_binary = "/usr/bin/md5sum" ;
// todo: grant URL follow thingy if it hasn't been done already
if( count($argv)<2 || count($argv)>3 || in_array("-h", $argv) || in_array("--help", $argv) ) {
echo "usage: {$argv[0]} <file_name> [folder_id]\n\n where <file_name> is the full path to the file that you want to upload to Google Drive.\n and [folder_id] is the the folder where you want to upload the file (optional, defaults to root)\n\n" ;
exit( 1 ) ;
}
$file_name = $argv[1] ;
if( !file_exists($file_name) ) {
echo "ERROR: {$file_name} is not found on the filesystem\n" ;
exit( 1 ) ;
}