Google Reader, работаем из PHP

7 декабря, 2011

Качаем ericmann-gReader-Library с гитхаба.

Сразу проезжаемся рубанком, заменяя private на protected, иначе нельзя обратиться к методам и свойствам при расширении класса extends.

Задача: вытянуть из Google Reader записи, отмеченные звёздочками (starred) и отослать информацию о снятии звёздочки

Решение, расширяем базовый класс двумя методами:

include_once 'ericmann-gReader-Library/greader.class.php';
 
class google_reader extends JDMReader
{
	public function __construct() 
	{
 
	}
 
	public function connect($username, $password)
	{
		parent::__construct($username, $password);
	}
 
	// List a particular number of unread posts from the user's reading list
	public function getStarred($limit) {
		$gUrl = 'http://www.google.com/reader/api/0/stream/contents/user/-/state/com.google/starred';
		$args = sprintf('n=%2$s&ck=%3$s&client=GoogleReaderDashboard', time() - (7*24*3600), $limit, time());
 
		$data = $this->_httpGet($gUrl, $args);
 
		$decoded_data = json_decode($data, true);
		$feed_items = $decoded_data['items'];
 
		return($feed_items);
	}
 
	/**
	  * Mark this an item as unstarred
	  *
	  * This method marks an item as unstarred for a certain user.
	  *
	  * @param string $itemId  The item id that can be retrieved from $this->listAll()
	  *
	  * @return boolean
	  */
 
	public function markAsUnstarred($itemId) {
		$data = sprintf(
			'i=%1$s&T=%2$s&r=%3$s&ac=edit', 
			$itemId, $this->_token,'user/-/state/com.google/starred'
		);
 
		$path = '/reader/api/0/edit-tag?client=-';
		$host = 'www.google.com';
 
		$response = $this->_httpPost($host, $path, $data);
		if($response == null) return false;
		return true;
	}
 
}

юзаем:

		$this->load->library('google_reader');
		$this->google_reader->connect('login@gmail.com','******');
 
		if ($this->google_reader->loaded)
		{
			print_r($this->google_reader->getStarred(10));
		}

Оставить комментарий

© 2010 - 2024 Ядоблог. Ничего не защищено.
Powered by Лаборатория Яда. Написать Яду