EzDevInfo.com

phpflickr

PHP Wrapper for the Flickr API

Using Flickr to Enable Images on a Site

Has anyone had success using Flickr to embed images that users can upload to my site, but that are hosted on Flickr?

Is something like this possible?

Thanks, Alex


Source: (StackOverflow)

can you store flickr images from the php api to your own mysql table

can you store flickr images from the php api to your own mysql table, or is the server only temporary and farm id etc, will they change over time?

I am trying to make a simple pinterest type of script which I will store the image url to a mysql table and link through to them directly on my website.

is this possible or do they need to be saved.


Source: (StackOverflow)

Advertisements

How do I get phpFlickr to return the original image?

This code works perfectly:

$f = new phpFlickr(FLICKR_API_KEY, FLICKR_API_SECRET);
$f->setToken(FLICKR_AUTH_TOKEN);
// Next line is just WordPress providing the photoset ID.
$mySetID = get_post_meta($post->ID, 'Flickr set ID', true); 
$mySet = $f->photosets_getPhotos($mySetID, NULL, NULL);
foreach ($mySet['photoset']['photo'] as $photo) {
    echo '<div><img src="'. $f->buildPhotoURL($photo, 'large') .'" alt="" /></div>';
}

...until buildPhotoURL is told to fetch the "original" size, at which point the URL returned is something like "http://farm6.static.flickr.com/5607/5332878962__o." which is obviously not valid.

While everything I've found through searches seems to agree that doing this requires some "originalsecret" and "originalformat" values that are barely mentioned in Flickr's own documentation, and phpFlickr does seem to try and use them, they're clearly not being fetched by default and I've yet to see someone post code for how to actually provide them. I've tried calling $f->photos_getInfo() just before the echo line, passing in various things to no effect and I'm starting to feel like I'm missing something everyone thinks is obvious, even though nobody has ever produced a valid response(that I can find) to repeated questions about it on the phpFlickr forum.

Note:

  • This is a Pro account.
  • We are authenticating properly(these are private sets and they work fine for all other sizes).
  • Access to the original size in Flickr's privacy settings is set to "Anyone."

Ideas?


Source: (StackOverflow)

phpFlickr and getting images from Flickr

I'm trying to pull in images from Flickr using the phpFlickr library but the docs seem to be quite vague and the results aren't as good as i would like, i wonder if anyone can shed some light on my code (maybe i'm using the wrong syntax?).

It works for some queries mainly 1 word queries, i.e. if i send the $tag "inter" it will find some photos on inter, but if i send "Inter Milan FC" it will not, even though a flickr search http://www.flickr.com/search/?w=all&q=inter+milan+fc&m=text clearly shows lots of inter milan fc photos.

Below is my implementation of the phpFlickr function....

function flickr_feed ( $tag ) {
    $f = new phpFlickr("MY API KEY", "MY API SECRET");
    $tags = $f->photos_search(array("tags"=>$tag, "tag_mode"=>"any","per_page"=>"20"));
    $counter="0";
    foreach ($tags['photo'] as $photo) {
    	if($counter =="0" || $counter =="5" || $counter =="10" || $counter =="15") { $first = " first"; } else { $first = ""; }
    	echo '<div class="flickr-thumb'.$first.'">
    			<a rel="nofollow" target="_blank" rel='nofollow' href="http://farm'.$photo['farm'].'.static.flickr.com/'.$photo['server'].'/'.$photo['id'].'_'.$photo['secret'].'.jpg" title="'.$photo['title'].'">
    			<img src="http://farm'.$photo['farm'].'.static.flickr.com/'.$photo['server'].'/'.$photo['id'].'_'.$photo['secret'].'_s.jpg" alt="'.$photo['title'].'"></a>
    		</div>';
    	$counter++;		
    }
}

I am also open to using other means of getting images from flickr (and not just phpflickr), i merely want to send a search to flickr and get a list of images, ideally i can control the amount that come back! that's it really, a simple task that is proving quite difficult :(


Source: (StackOverflow)

flic.kr/s/ short url for sets base58 issue

I am having trouble with flickr short urls, specifically those generated for sets.

Photos

I can see that for individual photos, if I select share and get the short url, they I would get flic.kr/p/{base58_encode(photoid)}. I can easily decode and encode the photoid and get the correct values.

Sets

I have tried the same for sets. If I select share on a set and get the short url, then I would get something like flic.kr/s/{base58_encode(setid)}. However, I am not sure that it is base58 encoded this time as decoding/encoding setid's with a base58 encoder/decoder does not return the correct values.

So, the question is, are the setid's encoded with a different encoder, or is there some sort of salt used with sets?

Many thanks in advance.


Source: (StackOverflow)

phpFlickr Caching to Filesystem or MySQL?

Are you supposed to be able to see distinct filenames via phpFlickr's caching to filesystem or MySQL? I've set the parameters as listed in the readme, but caching does not seem to generate any files or mysql table rows.

I've tried both the filesystem (chmod 777 in cache folder) and mysql method (manually created cache table). Any advice on what's to be done to enable caching on phpFlickr ? http://phpflickr.com/docs/caching/

$f = new phpFlickr($key);

$f->enableCache("db", "mysql://user:password@localhost/database");

Source: (StackOverflow)

phpflickr - photos_getInfo very slow

I'm using phpflickr to retrieve images from Flickr. For some reason photosets_getPhotos doesn't contain the image descriptions and photos_getInfo has to be used instead. However, when I do it slows everything right down.

Here is a function I've made to retrieve an image set and display it in a prettyPhoto list.

function flickrGallery($setId,$ulClass,$prettyPhotoGroup){

   $f = new phpFlickr('KEY','SECRET',false); // API
   $user = "USERID";

   $photoset_id = $setId;
   $photos = $f->photosets_getPhotos($photoset_id);

   echo "<ul class=\"$ulClass\">\n";

   foreach ($photos['photoset']['photo'] as $photo){
      $getInfo = $f->photos_getInfo($photo['id']);
      $description = $getInfo['photo']['description'];

      $urlOrig = $f->buildPhotoURL($photo, "small");
      $urlHex = strToHex($urlOrig);
      $fullsize = $f->buildPhotoURL($photo, "large");

      echo "<li>"
          ."<a rel='nofollow' href=\"$fullsize\" rel=\"prettyPhoto[$prettyPhotoGroup]\" title=\"".$description."</pre>\">"
          ."<img src=\"/thumb/external$urlHex/120/86\" width=\"120\" height=\"80\" class=\"borderoff\" alt=\"".$photo['title']."\" />"
          ."</a>"
          ."</li>\n";
   }

   echo "</ul>\n";
}

Is there a way I can speed things up or an alternative method for getting the image descriptions?


Source: (StackOverflow)

flickr api search does not work for a subset of pictures

I'm building a website that takes data from flickr and displays it in a custom front-end. The search using flickr.photos.search does not work for some queries, but it does for another:

It does not work for "blossom"

produces no results results. However, http://www.flickr.com/photos/elizabeth_malara/tags/blossom/ displays correct results (and proves that images are visible to the public)

But it works for "farm"

produces same results as http://www.flickr.com/photos/elizabeth_malara/tags/farm

We can see selective behavior of the search API call. Why does it happen? Also, the API search doesn't work whether I search by "tags" or "text"

All the pictures are public and not flagged. Tag "blossom" was added a week after tag "farm" but that was all over a month ago

thank you


Source: (StackOverflow)

Including the phpFlickr library in Kohana

I'm beginning a website using the Kohana Framework, and I couldn't find how to include external libraries "the proper way".

I want to use the phpFlickr library to allow my website to interact with Flickr.

If there was a better way to include the files than:

require_once("path/to/phpFlickr.php");
// Fire up the main phpFlickr class
$f = new phpFlickr($key);

It's OK to do it that way I guess, but if I could say to Kohana, "the phpFlickr files are there, go get them on your own when you need it", it would be better.

Anyone can help me with that?

Thanks.


Source: (StackOverflow)

Flickr API returning duplicate images

I'm trying to get images from flickr using the Flickr API and I'm having trouble figuring out how to get only unique images. I've already reviewed the arguments for the specific method that I'm using and here's what I came up with:

<?php
class Flickr {

    private $flickr_key;
    private $flickr_secret;
    private $format = 'json';

    public function __construct( $flickr_key, $flickr_secret ) {

        $this->flickr_key = $flickr_key;
        $this->flickr_secret = $flickr_secret;
    }


    public function searchPhotos( $query = '', $tags = '' ) {

        $urlencoded_tags = array(); 

        $tags_r = explode(',', $tags);
        foreach($tags_r as $tag){
            $urlencoded_tags[] = urlencode($tag);
        }

        $url = 'http://api.flickr.com/services/rest/?';
        $url .= 'method=flickr.photos.search';
        $url .= '&text=' . urlencode($query);
        $url .= '&tags=' . implode(',', $urlencoded_tags);
        $url .= '&sort=relevance';
        $url .= '&safe_search=1';
        $url .= '&content_type=4';
        $url .= '&api_key=' . $this->flickr_key;
        $url .= '&format=' . $this->format;
        $url .= '&per_page=10';
        $url .= '&media=photos';
        $url .= '&privacy_filter=1';

        $result = @file_get_contents( $url );


        $json = substr( $result, strlen( "jsonFlickrApi(" ), strlen( $result ) - strlen( "jsonFlickrApi(" ) - 1 );

        $photos = array();
        $data = json_decode( $json, true );
        if($data['stat'] != 'fail'){
            $photos = $data['photos']['photo'];
            return $photos;
        }else{
            return false;
        }
    }
}

And I'll just call it in like:

$flickr = new Flickr($flickr_key, $flickr_secret);

$query = 'Kaspersky Internet Security 2013';
$tags = 'software';

$results = $flickr->searchPhotos($query, $tags);
foreach($results as $img){
    $src = "http://farm" . $img['farm'] . ".static.flickr.com/" . $img['server'] . '/' . $img['id'] . '_' . $img['secret'] . '_m.jpg';
?>
  <img src="<?php echo $src; ?>"/>
<?php
}

The problem here is that I'm getting duplicate images from time to time. I also tried using the phpflickr library. But I'm still having the same issues:

$flickr = new phpFlickr($api_key);

$args = array(
    'text' => 'Kaspersky Internet Security 2013',
    'tags' => 'software',
    'per_page' => '10',
    'safe_search' => '1',
    'content_type' => '4',
    'media' => 'photos',
    'sort' => 'relevance',
    'privacy_filter' => '1'
);

$results = $flickr->photos_search($args);

$hashes = array();
$sources = array();

$images = $results['photo'];

foreach($images as $img){

    $src = "http://farm" . $img['farm'] . ".static.flickr.com/" . $img['server'] . '/' . $img['id'] . '_' . $img['secret'] . '_m.jpg';

    $current_hash = sha1_file($src);


    if(!in_array($current_hash, $hashes)){
?>
    <img src="<?php echo $src; ?>" alt="">
<?php       
    }

    $hashes[] = $current_hash;
}

As you can see from the above code I've used sha1_file method to compare the hashes of each of the images returned from flickr. But that's a big performance hit:

without sha1_file: 0.81311082839966
with sha1_file: 6.8974900245667 

Any ideas what else can I do to prevent flickr from returning duplicates? As you can see I'm only returning 10 images and that's all I need. I've also tried to add as many arguments that matches my needs but still no luck. Thanks in advance!


Source: (StackOverflow)

Flickr API: How to (successfully) get push notification for new photos(private) with specific tags?

I am using this php library for flickr. I have added following flickr push_subscription function:

function push_subscribe ($topic = NULL, $callback = NULL, $verify = NULL, $verify_token = NULL, $lease_seconds = NULL, $tags = NULL) {

return $this->call('flickr.push.subscribe', array('topic' => $topic, 'callback' => $callback, 'verify' => $verify, 'verify_token' => $verify_token, 'lease_seconds' => $lease_seconds, 'tags' => $tags)); 
}

After that have subscribed to push notification with topic set as "tags":

$res = $f->push_subscribe("tags", "http://mysite.herokuapp.com/flickr/push-notification.php", "async", NULL, NULL, "personal");

After subscription with getsubscription i got response like:

[0] => Array ( [topic] => tags [callback] => mysite.herokuapp.com/flickr/push-notification.php [pending] => 1 [date_create] => 1435469765 [expiry] => 0 [verify_attempts] => 1 )

[stat] => ok

My callback url is a php script on my site:

<?php
if (isset($_GET['hub_challenge'])) {
  print $_GET['hub_challenge'];
}
else {
  $xml=file_get_contents("php://input");
  file_put_contents('endpoint.txt',$xml);
}

However I do not get anything after I upload new photo with specific tag? The endpoint.txt file is empty.Why?

What am I missing?


Source: (StackOverflow)

Flickr Upload Video PHP

I am trying to upload a video to my Flickr account using PHP. The PHP script is running on my localhost server.

I have downloaded a .php library to assist me

https://github.com/dan-coulter/phpflickr

I have created a Flickr account and created an 'app' I have my api key and secret key. I have set my app as a "web application" and set my callback to 127.0.0.1:80 This has worked on several other file sharing hosts, so I thought it may work on Flickr

Here is my code

function uploadFlickr( $fileToSave , $fileName , $fileDesc , $fileTags ) {

require_once 'flickr/phpFlickr.php';

$consumer_key = "key";
$consumer_secret = "secretkey";

$flickr = new phpFlickr($consumer_key,$consumer_secret, true);

if(empty($_GET['frob'])) {
    $flickr->auth('write');
}
else {
    $flickr->auth_getToken($_GET['frob']);
}

$resu = $flickr->sync_upload( $fileToSave , $fileName , $fileDesc , $fileTags );

echo "<pre>"; print_r($resu);
}

So firstly, the example script provided in the gitHub library doesn't seem to like the callback url. I get the auth request path, I hit accept and then it kicks me to an error page.

 Oops! Looks like you followed a bad link. 

No other error info.

Also, Most other file sharing hosts allow a direct authentication by passing a username and password so I can upload directly to my own account.

My app will not work if I have to manually accept uploads to my own account. It needs to be automated.

Is this possible with Flickr using PHP?

Any help would be great, thanks.


Source: (StackOverflow)

Message: Invalid argument supplied for foreach() for Flickr

I recently switched our site to a different server for ExpressionEngine and all of a sudden I'm getting errors when trying to access a drop down list of Flickr albums.

This is what the error says:

A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: flickr_sets/ft.flickr_sets.php Line Number: 35

Here is the code for the php file...line 35-37

foreach($sets['photoset'] as $photoset) {
$photo_sets[$photoset['id']] = $photoset['title'];
}

I haven't changed anything but am wondering if I need to reauthorize the token since I switched to a different server.

Anyone has any idea?


Source: (StackOverflow)

phpFlickr proxy not working call to member function error

I have downloaded and setup phpFlickr library but I need to use it from behind a proxy, so I have added the line to the example file and it throws an error. As its all pretty much out of the box, im flumaxed I also dont get the call to member function on a non object error it completely baffles me.

The readme paragraph

  1. Some people will need to ues phpFlickr from behind a proxy server. I've implemented a method that will allow you to use an HTTP proxy for all of your traffic. Let's say that you have a proxy server on your local server running at port 8181. This is the code you would use: $f = new phpFlickr("[api key]"); $f->setProxy("localhost", "8181"); After that, all of your calls will be automatically made through your proxy server.

The example.php file with my single modified line

require_once("phpFlickr.php");
$f = new phpFlickr("********************");
$f->setProxy("cache.mysite.org.uk", "80");

$recent = $f->photos_getRecent();

foreach ($recent['photo'] as $photo) {

$owner = $f->people_getInfo($photo['owner']);
echo "<a rel='nofollow' href='http://www.flickr.com/photos/" . $photo['owner'] . "/" . $photo['id'] . "/'>";
echo $photo['title'];
echo "</a> Owner: ";
echo "<a rel='nofollow' href='http://www.flickr.com/people/" . $photo['owner'] . "/'>";
echo $owner['username'];
echo "</a><br>";

}

Any idea why im getting the following error Call to a member function setProxy() on a non-object in public_html/phpFlickr/phpFlickr.php on line 338

That code is

#336    function setProxy ($server, $port) {
#337            // Sets the proxy for all phpFlickr calls.
#338            $this->req->setProxy($server, $port);
    }

Source: (StackOverflow)

PHP: Download images from Flickr to local server (via CURL?)

I’ve a Wordpress site where I uses my Flickr feed to get my latest images. By using a script, I create a new post everytime I’ve a new image on Flickr but, the image thumbnail source is from Flickr and when I press the thumbnail I’m redirected to the Flickr image.

I want to close down my wordpress site for any new content and want to close it off from all third part APIs and Services, so I want to run through my list of Flickr posts and download every thumbnails and images I’m referring to.

An example of a Flickr post on my blog with an image looks like this:

<a rel='nofollow' href="http://www.flickr.com/photos/2332432@N06/554435234/">
<img alt="My ALT text" src="http://farm8.staticflickr.com/2213/35554564_5fhe10fj22_m.jpg"
</a>

If it can be done I would like to download both the thumbnail and the large picture but otherwise an acceptable solution would be just to download the thumbnail image (the image from farm8.staticflickr.com).

I’ve tried different approached but none have worked. One I tried was this (which I’m using to extract the Vimeo thumbnail, so therefor I thought I would work on the Flickr Thumbnail):

$ch = curl_init($the-image-url-variable);
$fp = fopen('$thename.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

When I’m using this code, it does indeed generate an image in my folder but the image is invalid and can’t show any content..

Any help or suggestions would be appreciated.

Sincere
- Mestika


Source: (StackOverflow)