zebrello/feedly-api

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP library to use Feedly Cloud API

1.0.0 2015-04-23 22:10 UTC

This package is not auto-updated.

Last update: 2018-02-18 11:52:13 UTC


README

Scrutinizer Code Quality

Simple PHP library to use Feedly Cloud API based on Guzzle

Requirements

Installation

Using Composer

To install feedly-api with Composer, just add by running the following command:

composer require zebrello/feedly-api

Composer installs autoloader at ./vendor/autoloader.php. to include the library in your script, add:

require_once 'vendor/autoload.php';

If you use Symfony2, autoloader has to be detected automatically.

You can see this library on Packagist.

Usage

Authenticate to your feedly cloud account

use FeedlyApi\Client;

// The sandbox client id and client secret are posted once a month on the feedly cloud forum:  https://groups.google.com/forum/#!forum/feedly-cloud.
// More info on https://developer.feedly.com/v3/sandbox/
// If using the sandbox set $sandboxMode to true | default is false

$client = new Client($clientId, $clientSecret, $redirectUri, $sandboxMode);
$loginUrl = $client->getLoginUrl();

// Redirect to the loginUrl to authenticate
header('Location: '. $loginUrl);

Handling the response

use FeedlyApi\Client;

$client = new Client($clientId, $clientSecret, $redirectUri, $sandboxMode);

// The response will be sent to the $redirectUri

if($_GET['code']){
  $client->auth($_GET['code']);

  // Get the accessToken and save it to the session
  $_SESSION['feedlyAccessToken'] = $client->getAccessToken();
}

Request example (profile)

use FeedlyApi\Client;

$client = new Client($clientId, $clientSecret, $redirectUri, $sandboxMode);

// Set the accessToken from session
$client->setAccessToken($_SESSION['feedlyAccessToken']);

$profile = $client->call('profile');

Example in Symfony get categories and rename first category to 'test'

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use FeedlyApi\Client;
use GuzzleHttp\Exception\ClientException;

class DefaultController extends Controller
{
    /**
     * @Route("/")
     */
    public function indexAction(Request $request)
    {
        $session = $request->getSession();
        $client = new Client('sandbox', '4205DQXBAP99S8SUHXI3', $this->get('router')->generate('app_default_index', array(), true), true);
        if($request->query->has('code')){
            $client->auth($request->query->get('code'));
            $session->set('feedlyAccessToken', $client->getAccessToken());
        }

        if($session->has('feedlyAccessToken')){
            $client->setAccessToken($session->get('feedlyAccessToken'));
        }

        try {
            $categories = $client->call('categories');
            $body = array(
                'label' => 'Test',
            );
            $response = $client->call('categories', $categories[0]['id'], 'post', $body);
            return new JsonResponse($response);
        } catch (ClientException $e){
            return new JsonResponse($e->getResponse()->json());
        } catch (\Exception $e){
            $loginUrl = $client->getLoginUrl();
            return $this->redirect($loginUrl);
        }
    }
}

Contributing

See CONTRIBUTING file.

License

feedly-api is released under the MIT License. See the bundled LICENSE file for details.