jaykay-design/cakephp-my-instagram-feed

CakePHP3.x Instagram feed Plugin

dev-master 2020-02-03 10:25 UTC

This package is auto-updated.

Last update: 2024-05-29 04:41:20 UTC


README

Show your own Instagram feed in CakePHP

Table of Contents

Installation

You can install this plugin into your CakePHP application using composer.

Run the following command

composer require jaykay-design/cakephp-my-instagram-feed

You can then load the plugin using the shell command:

bin/cake plugin load -b MyInstagramFeed

Or you can manually add the loading statement in the config/boostrap.php file of your application:

Plugin::load('MyInstagramFeed', ['routes' => true]);

or in CakePHP >= 3.8 add this statement in the src/Application.php file of your application

public function bootstrap()
    {
        ...
        $this->addPlugin(\MyInstagramFeed\Plugin::class, ['routes' => true]);
        ...

Add the view helper in src/View/AppView.php

public function initialize()
{

    ...
    $this->loadHelper('MyInstagramFeed.MyInstagramFeed');    
    ...

Preparation

To be able to get your Instagram feed data you will have to provide a client ID and client secret. These can be obtained by creating a Facebook App for Instagram. Follow these instructions.

When asked to provide an OAuth callback url enter this: [Your domain]/MyInstagramFeed/OAuth/authorize

Configuration

Default configuration:

'MyInstagramFeed' => [
    'client_id' => '',
    'client_secret' => '',
    'cache_config' => 'default'
],
  • client_id (string) - The client id provided to you when you set up the app
  • client_secret (string) - The client secret provided to you when you set up the app
  • cache_config - The cache configuration for the instagram feed data

Basic Usage

Typically you define these keys in your config/app.php file:

'MyInstagramFeed' => [
    'client_id' => 'some large number',
    'client_secret' => 'a very large string',
    'cache_config' => 'default'
],

Once you have Installed and configured the plugin visit this page of your site: [your domain]/MyInstagramFeed/OAuth and you will be shown a link named "Authorize". After you click on it you will be asked if this app is allowed to access your Instagram feed. Agree to all options.

In your template where you want to show your Instagram feed add this code:

<?php 
    $items = $this->MyInstagramFeed->getItems();
    foreach ($items as $item) { ?>
    <a href="<?=$item['permalink']?>">
        <img 
            src="<?=empty($item['thumbnail_url']) ? $item['media_url'] : $item['thumbnail_url'] ?>" 
            alt="<?=$item['caption'] ?>" 
            title="<?=$item['caption'] ?>">
    </a>
<?php } ?>

Bugs and Feedback

https://github.com/jaykay-design/cakephp-my-instagram-feed/issues

License

Copyright (c) 2017 John Caprez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.