php library for flickr API

倖福魔咒の 提交于 2019-12-23 03:12:55

问题


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".

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.

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?


回答1:


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

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

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..

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

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.

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.

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"

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."

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).

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

That's it. (-:



来源:https://stackoverflow.com/questions/37975567/php-library-for-flickr-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!