用于flickr API的php库 [英] php library for flickr API

查看:74
本文介绍了用于flickr API的php库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力尝试使用Flickr API ... 我的目标是能够从我的网站上的Flickr帐户中上传图片并创建相册... 我尝试了 phpFlickr 库,但显然它需要更新以获取经过身份验证的令牌...它不断给我无效的身份验证令牌".

I am banging my head trying to use Flickr API... My goal is to be able to upload images and create albums in my Flickr account from my website... I tried the phpFlickr library but apparently it needs updates for getting authenticated tokens...It keeps giving me "Invalid auth token".

我对如何获取令牌和使用 DPZFlickr 进行了一些阅读,从而设法获得了oauth_token& oauth_verifier,但无法与访问令牌交换该密码...它也无法使用随附的upload.php示例将任何照片上传到我的帐户(给我一个空"错误!). 在探究DBZ flickr.php代码之后,尝试上传到Flickr时,我设法得到此错误:"oauth_problem = signature_invalid&" 因此,我开始研究如何创建有效的签名以最终获得有效的访问令牌……并得出结论,如果我要从头开始构建所有内容,则需要在这里完成很多工作.

I did some reading on how to get tokens and using DPZFlickr managed to get oauth_token & oauth_verifier but failed to exchange that with an access token...It also failed in uploading any photo to my account using the included upload.php example (Giving me an "empty" error!). After digging in DBZ flickr.php code, I managed to get this error when trying to upload to Flickr: "oauth_problem=signature_invalid&" So I began to search how to create a valid signature to eventually get a valid access token...and concluded that it is quite some work to be done here if I am going to build everything from scratch.

所以我的问题是:是否有可以用来成功创建相册并将照片上传到我的Flickr帐户的任何更新的php库?还是我应该尝试构建一个?

So my question is: Are there any updated php libraries that I can use to successfully create albums and upload photos to my Flickr account? Or should I go ahead and try building one?

推荐答案

好的.我终于可以将其与DPZ库一起使用了.

OK..I finally got it to work with the DPZ library.

任何面临与我相同问题的人以供将来参考:

For future reference anybody facing the same problem as I had:

通过将auth.php中的方法更改为flickr.photosets.create ...,我设法使用DPZFlickr创建了一个相册,这表明该库正确生成了具有写许可权的访问令牌.

I managed to create an album using DPZFlickr by changing the method in auth.php to flickr.photosets.create....which indicated that the library correctly generates an access token with write permission..

但是,上传示例一直给我无效签名"错误.... 我检查了代码. Flickr.php在对请求进行签名之前正确地取消设置了photo参数,然后将其重新添加并提交了请求,该请求与以下网址中的指示完全相同:www.flickr.com/services/api/upload.api.html

However, the upload example kept giving me the "Invalid signature" error.... I checked the code. Flickr.php correctly unsets the photo parameter before signing the request then adds it back and submits the request which is exactly as indicated in: www.flickr.com/services/api/upload.api.html

我在 https://www.flickr.com中找到了讨论/groups/51035612836 @ N01/discuss/72157650261711318/清除了该错误实际上不是签名问题,而是所发送的照片"参数是问题所在.只是Flickr不知道要使用photo参数做什么,因此它会发送签名错误.

I found a discussion in https://www.flickr.com/groups/51035612836@N01/discuss/72157650261711318/ that cleared out that the error was not actually a signature problem, but rather the 'photo' parameter that is being sent is the problem. It's just that Flickr doesn't know what to do with the photo parameter so it sends the signature error.

那么photo参数怎么了? Flickr API要求图像必须以二进制格式发送... DBZ库Flickr.php脚本行677使用php中的cURL函数为我们完成了艰苦的工作(

So what' wrong with the photo parameter? Flickr API requires that the image has to be sent in binary form...The DBZ library, Flickr.php script line 677, does the hard work for us using the cURL function in php (http://au.php.net/manual/en/function.curl-setopt.php). It sends the $parameters (which includes the uploaded photo) to the post field of the http request which should do the upload in binary format for us.

但是,我在 CURL PHP发送图像中发现了一个很棒的评论 指出: 在5.6.0中CURLOPT_SAFE_UPLOAD默认为true ...,因此在设置CURLOPT_POSTFIELDS之前,您需要添加curl_setopt($ ch,CURLOPT_SAFE_UPLOAD,false);"

However, a brilliant comment I found in CURL PHP send image states that: "CURLOPT_SAFE_UPLOAD defaulted to true in 5.6.0... so you will need to add curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); before setting CURLOPT_POSTFIELDS"

检查手册: http://au.php.net /manual/zh-CN/function.curl-setopt.php 它说: 在PHP 5.5.0中添加了FALSE作为默认值.PHP5.6.0将默认值更改为TRUE."

Checking the manual: http://au.php.net/manual/en/function.curl-setopt.php it says: "Added in PHP 5.5.0 with FALSE as the default value. PHP 5.6.0 changes the default value to TRUE."

因此,如果您的php版本为5.5.0,则该库将运行良好,而如果使用版本为PHP 5.6.0,则需要在Flickr.php中的677之前添加一行以将CURLOPT_SAFE_UPLOAD更改为false(这就是该库起作用的原因而有些则没有).

So if your php version is 5.5.0 the library will work just fine whilst if using version PHP 5.6.0 you need to add a line before 677 in Flickr.php to change the CURLOPT_SAFE_UPLOAD to false (that's why the library works with some and others not).

要解决此问题...只需在Flickr.php中的第677行之前添加以下行: curl_setopt($ curl,CURLOPT_SAFE_UPLOAD,false);

To solve the issue...Just add this line before line 677 in Flickr.php: curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);

就是这样. (-:

这篇关于用于flickr API的php库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆