使用没有Google云端硬盘的Google Api云端硬盘

时间:2014-04-03 19:59:22

标签: php google-drive-api

我需要知道Google云端硬盘的文件是否有自己的ID。我想知道这个文件是" public"。

我尝试了Google API云端硬盘,并要求我使用Google帐户登录。问题是我正在做的代码是匿名用户。

基本上我想知道照片是否已发布,是否显示照片是私密的警告。

我如何用PHP做到这一点?。

2 个答案:

答案 0 :(得分:1)

required登录Google帐户。

  

对Google Drive API的所有请求必须经过授权   经过身份验证的用户。

但是,您至少有两个选择:

  • 第一个选项是使用您自己的帐户来检查文件。如果您只是需要检查它是否已发布,您可以使用您的帐户从服务器发出呼叫。
  • 第二个选项是发出此curl命令来检查返回值curl --head https://googledrive.com/host/$fileID

    • $fileID是您已有的文件ID。您正在寻找状态响应: HTTP/1.1 200 OK

    如果您获得200以外的任何内容,则该文件不可用。

答案 1 :(得分:0)

require_once 'src/Google_Client.php';
require_once 'src/contrib/Google_DriveService.php';

$client = new Google_Client();
// Get your credentials from the console
$client->setClientId('xxxxx');
$client->setClientSecret('xxxx');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));


$service = new Google_DriveService($client);
echo 'Googlele';


function printFile($service, $fileId) {
  try {
    $file = $service->files->get($fileId);

    print "Title: " . $file->getTitle();
    print "Description: " . $file->getDescription();
    print "MIME type: " . $file->getMimeType();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}
if($service)
    {
        echo 'Connect';
         printFile($service, '0B2B9KL1Xm3swYmdkbTNqcFp4eE0');

    }

响应:

发生错误:调用GET https://www.googleapis.com/drive/v2/files/0B2B9KL1Xm3swYmdkbTNqcFp4eE0时出错:(403)超出未经身份验证的使用的每日限制。继续使用需要注册。

但实际上不可能达到极限,我不会做任何50次测试。

相关问题