插入文件Google drive wget

时间:2015-11-05 13:54:32

标签: php cron wget

当我通过浏览器执行时,我有来自Google驱动器和wordks的脚本,但是我想通过Wget执行它,但这不起作用。 为什么这不适用于wget?

$client = new Google_Client();
$client->setAuthConfig($oauth_credentials);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/drive");
$service = new Google_Service_Drive($client);

if (!empty($_SESSION['upload_token'])) {
  $client->setAccessToken($_SESSION['upload_token']);
  if ($client->isAccessTokenExpired()) {
    unset($_SESSION['upload_token']);
  }
}
else {
  $authUrl = $client->createAuthUrl();
}

DEFINE("TESTFILE", 'testfile-small.txt');

if (!file_exists(TESTFILE)) {
  $fh = fopen(TESTFILE, 'w');
  fseek($fh, 1024 * 1024);
  fwrite($fh, "!", 1);
  fclose($fh);
}

// This is uploading a file directly, with no metadata associated.
$file = new Google_Service_Drive_DriveFile();

$result = $service->files->insert(
  $file,
  array(
    'data' => file_get_contents(TESTFILE),
    'mimeType' => 'application/octet-stream',
    'uploadType' => 'media'
  )
);

1 个答案:

答案 0 :(得分:0)

如果您自己导航到网站,

wget会提取您收到的内容。这意味着,如果您在没有任何会话信息的情况下自己将链接放入浏览器,您将收到通常收到的任何内容。

您可以使用wget尝试--save-cookies。根据OAuth的工作原理,您可能还需要--header,很可能需要--referer(有关详细信息,请参阅here。有关示例,请参阅this SO post。)< / p>

这很复杂,本质上是为PHP脚本创建客户端包装器。有更好的方法

您可以使用php [your php script]在命令行上执行PHP文件(根据@ Oldskool&#39;评论)。请注意,这可能不起作用。

您还可以下载bashPowerShell的客户端。