创建 Picasa 相册并使用 PHP 和 cURL 将图像上传到其中
我发现的所有创建 Picasa 相册和上传图片的教程都使用我没有研究过的 Zend 框架。
是否可以使用 PHP 和 cURL 上传图像并创建相册?
我的图像存储在目录 e:/images
中,图像信息存储在 MySQL 表中,如下所示:
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATE TABLE IF NOT EXISTS `picasaimage` (
`id` bigint(1) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`content` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`tags` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`license` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`image_path` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
`width` int(4) COLLATE utf8_unicode_ci NOT NULL,
`height` int(4) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=0 ;
我使用以下代码获取 Google 客户端身份验证代码:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = array('accountType' => 'GOOGLE',
'Email' => '[email protected]',
'Passwd' => 'yourpassword',
'source'=>'PHI-cUrl-Example',
'service'=>'lh2');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$hasil = curl_exec($ch);
echo $hasil;
//SID=DQA...oUE
//LSID=DQA...bbo
//Auth=DQA...Sxq
?>
任何人都可以提供一些指导吗创建名为 test
的相册并将图像上传到其中?
EDIT1:
当我使用php脚本上传照片时如何添加照片许可证?
参考 http://commons.wikimedia.org/wiki/Commons:Picasa_Web_Albums_files
Creative Commons Attribution 3.0 Unported (CC-BY)
Creative Commons Attribution-Share Alike 3.0 Unported
Unlicensed
Creative Commons Attribution-Noncommercial 3.0 Unported
Creative Commons Attribution-No Derivative Works 3.0 Unported
Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported
检查 api get 的响应数据相册照片,应该有这样的内容:
"gphoto$license":{
"$t":"ATTRIBUTION_NON_COMMERCIAL_NO_DERIVATIVES",
"id":3,
"name":"Attribution-Noncommercial-No Derivative",
"url":"http://creativecommons.org/licenses/by-nc-nd/3.0"
},
All of the tutorials I've found for creating Picasa albums and uploading pictures use the Zend Framework which I haven't studied.
Is it possible to upload images and create albums using PHP and cURL?
My images are stored in the directory e:/images
and the image information is stored in a MySQL table like this:
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
CREATE TABLE IF NOT EXISTS `picasaimage` (
`id` bigint(1) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`content` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`tags` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`license` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`image_path` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
`width` int(4) COLLATE utf8_unicode_ci NOT NULL,
`height` int(4) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=0 ;
I'm getting the Google Client authentication code using the following code:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = array('accountType' => 'GOOGLE',
'Email' => '[email protected]',
'Passwd' => 'yourpassword',
'source'=>'PHI-cUrl-Example',
'service'=>'lh2');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$hasil = curl_exec($ch);
echo $hasil;
//SID=DQA...oUE
//LSID=DQA...bbo
//Auth=DQA...Sxq
?>
Can anyone give some guidance on creating an album named test
and uploading the images to it?
EDIT1:
How to add photo license when I upload photos with php scripts?
reference on http://commons.wikimedia.org/wiki/Commons:Picasa_Web_Albums_files
Creative Commons Attribution 3.0 Unported (CC-BY)
Creative Commons Attribution-Share Alike 3.0 Unported
Unlicensed
Creative Commons Attribution-Noncommercial 3.0 Unported
Creative Commons Attribution-No Derivative Works 3.0 Unported
Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported
Check the response data from api get album photo, there should be have something like:
"gphoto$license":{
"$t":"ATTRIBUTION_NON_COMMERCIAL_NO_DERIVATIVES",
"id":3,
"name":"Attribution-Noncommercial-No Derivative",
"url":"http://creativecommons.org/licenses/by-nc-nd/3.0"
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是创建相册的一些代码。我们将通过 cURL 调用进行身份验证。
上传照片的工作方式类似:
http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html#PostPhotos
以下是上传图片的功能代码没有元数据:
这是上传有元数据的照片的示例(最后!):
Here's some code for creating the album. We'll pick up with the cURL call to authenticate.
Uploading a photo works in a similar fashion:
http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html#PostPhotos
Here's functioning code for uploading an image without metadata:
And here's an example of uploading a photo with metadata (finally!):
扩展Mark的答案,您可以使用CURLOPT_POSTFIELDS直接从curl发送XML。但是,不要创建关联数组,而是尝试传递实际的 XML 字符串,如下所示:
Expanding Mark's answer, you can send the XML directly from curl using CURLOPT_POSTFIELDS. However, instead of making an associative array, try passing the actual XML string like so: