instaphplib/instaphplib

There is no license information available for the latest version (dev-master) of this package.

A Class for fetching your own user media from Instagram

dev-master 2014-11-27 15:09 UTC

README

Build Status Scrutinizer Code Quality Code Coverage

About

A Class for fetching your own user media from Instagram.

Get started

To use the Instagram API you have to register yourself as a developer at the Instagram Developer Platform. Please note that Instagram mainly refers to »Clients« instead of »Apps«. So »Client ID« and »Client Secret« are the same as »App Key« and »App Secret«.

Installation

Download Anax-MVC.

Add this to your composer.json in the Anax-MVC root.

"require": {
	"instaphplib/instaphplib": "dev-master"
},

Create a model called Instagram.php, like this:

<?php
namespace Anax\Instagrams;

class Instagram extends \instaphplib\instaphplib\Instagram implements \Anax\DI\IInjectionAware {

	use \Anax\DI\Tinjectable;

}

?>

Create a controller called IntagramsController.php. Change YOUR_USERID and YOUR_CLIENTID to your own credentials provided by Instagram:

<?php
namespace Anax\Instagrams;

/**
* Implement Instagram API to views.
*
*/
class InstagramsController implements \Anax\DI\IInjectionAware
{
	use \Anax\DI\TInjectable;

	public function initialize() 
	{	
		$this->instagrams = new \Anax\Instagrams\Instagram("YOUR_USERID", "YOUR_CLIENTID", "");
		$this->instagrams->setDI($this->di);
	}

	/**
	* Fetch Instagram media from specified user.
	*
	*/
	public function fetchImagesAction()
	{
		$userMedia = $this->instagrams->getUserMedia();

		$this->views->add('instagram/item-list', [
			'title' => 'Instagrambilder',
			'items' => $userMedia->data
		]);
	}
}
?>

Then create a view called item-list.tpl.php, like this:

<h1><?=$title?></h1>
<?php foreach ($items as $item) :?>

	<div class="insta-wrapper">
		<img src="<?=$item->images->thumbnail->url?>" class="insta-img">
		<div class="insta-like">
			<?= $item->likes->count ?>
		</div>
	</div>
<?php endforeach; ?>

Add this to your front controller:

$di->set('InstagramsController', function() use ($di) {
    $controller = new \Anax\Instagrams\InstagramsController();
    $controller->setDI($di);
    return $controller;
});

Add this to the route that you want your Instagram media to appear on:

$app->dispatcher->forward([
	'controller' => 'instagrams',
	'action' => 'fetchimages'
]);

Add this to your composer.json in the Anax-MVC root.

"autoload": {
    "classmap": [
        "app/src",
        "vendor"
    ]
},