dr6673999 2015-11-05 13:54
浏览 59

插入文件Google drive wget

I have a script from Google drive and wordks fine when i executing by browser, but i want to execute it by Wget, but that doesn't work. Why does this not work with 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条回答 默认 最新

  • douao1579 2015-11-05 14:13
    关注

    wget pulls what you'd receive if you navigated to a website yourself. That means that you'd receive whatever you'd normally receive were you to put the link into the browser yourself without any session information.

    You can try wget with --save-cookies. Based on how OAuth works, you'll probably also need --header, and quite possibly --referer (for details see here. For an example see this SO post.)

    This is complicated and is essentially creating a client wrapper for a PHP script. There is a better way.

    You can execute a PHP file on a command line by using php [your php script] (as per @Oldskool's comment). Note that this may not work.

    You can also download a client for bash or PowerShell.

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?