简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM