zebrello / feedly-api
此包已被弃用且不再维护。未建议替换包。
用于使用Feedly Cloud API的PHP库
1.0.0
2015-04-23 22:10 UTC
Requires
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2018-02-18 11:52:13 UTC
README
Simple PHP library to use Feedly Cloud API based on Guzzle
要求
- cURL
- PHP 5.4+
安装
使用Composer
要使用Composer安装feedly-api,只需运行以下命令
composer require zebrello/feedly-api
Composer在./vendor/autoloader.php
安装自动加载器。要将在脚本中包含库,请添加
require_once 'vendor/autoload.php';
如果你使用Symfony2,自动加载器必须自动检测。
你可以在Packagist上查看此库。
使用方法
验证你的Feedly云账户
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);
处理响应
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(); }
请求示例(配置文件)
use FeedlyApi\Client; $client = new Client($clientId, $clientSecret, $redirectUri, $sandboxMode); // Set the accessToken from session $client->setAccessToken($_SESSION['feedlyAccessToken']); $profile = $client->call('profile');
示例:在Symfony中获取类别并将第一个类别重命名为'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); } } }
贡献
许可协议
feedly-api在MIT许可证下发布。有关详细信息,请参阅附带的LICENSE文件。