maan81
maan81

Reputation: 3609

Accessing Flickr API in CLI

I am using phpfickr and need to run it in CLI.

But when executing $ php getToken.php, but I'm not being able to getting authenticated. I have the $app_id and $secret.

Please, I am new to this and haven't found a correct solution.

Upvotes: 1

Views: 354

Answers (2)

maan81
maan81

Reputation: 3609

Based on issue https://github.com/dan-coulter/phpflickr/issues/48 , adding

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

got me going.

This issue appears to be merged into master branch, but it does not exist.

Upvotes: 1

Chris
Chris

Reputation: 137169

The phpFlickr library you've linked to is very old.

If you really want to use this library it should be as simple as

<?php

require_once __DIR__ . '/phpflickr/phpFlickr.php';

// Make sure to fill in your API key and secret!
$flickr = new phpFlickr('your-api-key-goes-here', 'your-api-secret-goes-here');

The getToken.php file that you referenced does this. Perhaps you forgot to fill in your API key and secret?

Once you have your $flickr object you can use it to interact with Flickr's API. For example, you can do something like this to see titles of recently-posted public photos:

foreach ($flickr->photos_getRecent()['photos']['photo'] as $photo) {
    echo $photo['title'] . "\n";
}

However, there are more modern options. rezzza/flickr, for example, is available on Packagist and has over 16K installs. It uses modern PHP features like namespaces, __construct() constructors, and visibility keywords. It also seems to have a more sane API, though that's subject to opinion.

If you are already using Composer you should be able to composer require rezzza/flickr, then proceed as its README suggests. If you're not using Composer, start. It is an important part of the modern PHP ecosystem.

Upvotes: 4

Related Questions