在PHP中从Google Drive链接中获取图像

问题描述:

我想从php中的以下google驱动器url中提取图像,首先我需要获取html部分,然后获取img src,然后获取实际图像。但不知何故,我不能够得到HTML部分。我已经试过file_get_contentscurl请求。在PHP中从Google Drive链接中获取图像

网址 - https://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1

这里是我的卷曲脚本

<?php 
$url = "http://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$output = curl_exec($ch); 
curl_close($ch);  
print_r($output); 

输出

<HTML> 
<HEAD> 
<TITLE>Moved Permanently</TITLE> 
</HEAD> 
<BODY BGCOLOR="#FFFFFF" TEXT="#000000"> 
<H1>Moved Permanently</H1> 
The document has moved <A HREF="https://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1">here</A>. 
</BODY> 
</HTML> 

这里是我的PHP脚本使用的file_get_contents

<?php 

$url = "http://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1"; 

$html= file_get_contents($url); 

print_r($html); 

输出

Warning: file_get_contents(http://drive.google.com/file/d/0Bz14TICwUk77V25VQzd1MF8wLTQ/edit?pli=1): failed to open stream: No such file or directory on line 5 

和我了allow_url_fopen是在php.ini

任何帮助表示赞赏如此。

+2

看看:https://开头开发商。 google.com/drive/web/quickstart/quickstart-php – 2014-11-25 10:00:52

+1

特别是https://developers.google.com/drive/v2/reference/files/get和https://developers.google.com/drive/v2/reference/files – Gordon 2014-11-25 10:03:26

+0

您的http请求被重定向到https。使用https,那里不会是重定向。 – Henrik 2014-11-25 10:13:30

您的http请求被重定向到https。使用https,那里不会是重定向。

而是卷曲使用simplehtmldom的从谷歌刮数据驱动

这是一篇好文章

参考Link 1 & & Link 2