PHP Classes

PHP Instagram Feed Notification: Send Instagram posts by email

Recommend this page to a friend!
  Info   View files Example   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 49 This week: 1All time: 10,667 This week: 560Up
Version License PHP version Categories
ig-feed-notification 1.0.0MIT/X Consortium ...5Email, PHP 5, Social Networking
Description 

Author

This package can send Instagram posts by email.

It provides classes that store posts retrieved from an Instagram user feed in a database table.

The package can also return posts stored in the database and send them to a given email address.

The package retrieves the destination email address of these messages from environment variables.

Innovation Award
PHP Programming Innovation award nominee
November 2022
Number 6
Some people avoid spending too much time on social networks when they consider those social networks a distraction that is not worth their time.

Still, those who want to follow specific profiles would prefer following those profiles if they did not have to go daily to the profile pages.

This package provides a solution that sends email messages only when new posts of specific Instagram profiles are published.

Manuel Lemos
Picture of Chun-Sheng, Li
  Performance   Level  
Name: Chun-Sheng, Li <contact>
Classes: 27 packages by
Country: Taiwan Taiwan
Age: 30
All time rank: 22646 in Taiwan Taiwan
Week rank: 411 Up2 in Taiwan Taiwan Up
Innovation award
Innovation award
Nominee: 13x

Winner: 1x

Example

<?php

date_default_timezone_set
('Africa/Lagos');

require_once
__DIR__ . '/./vendor/autoload.php';

use
Instagram\Storage\CacheManager;
use
Instagram\Api;
use
Dotenv\Dotenv;
use
IgFeedNotification\CheckPost;
use
IgFeedNotification\SendMail;

@
mkdir('./ig_cache');

$cache = new CacheManager('./ig_cache');

$userNamesInstruction = [
   
'user_name1' => 'Give him 10k Likes',
   
'user_name2' => 'Give 10 comments',
];

foreach (
$userNamesInstruction as $userName => $instruction) {
   
$api = new Api($cache);

   
$api->setUserName($userName);

   
$dotenv = new Dotenv(__DIR__);
   
$dotenv->load();

   
$checkPost = new CheckPost();

    try {
       
// First page

        /** @var \Instagram\Hydrator\Component\Feed $feed */
       
$feed = $api->getFeed();

        echo
'============================' . "<br/>";

        echo
'User Informations : ' . "<br/>";
        echo
'============================' . "<br/><br/>";

        echo
'ID : ' . $feed->getId() . "<br/>";
        echo
'Full Name : ' . $feed->getFullName() . "<br/>";
        echo
'UserName : ' . $feed->getUserName() . "<br/>";
        echo
'Following : ' . $feed->getFollowing() . "<br/>";
        echo
'Followers : ' . $feed->getFollowers() . "<br/><br/>";

        echo
'============================' . "<br/>";
        echo
'Medias first page : ' . "<br/>";
        echo
'============================' . "<br/><br/>";

       
$msg = '';

       
/** @var \Instagram\Hydrator\Component\Media $media */
       
foreach ($feed->getMedias() as $media) {
           
$msg .= 'User Name : ' . $feed->getUserName() . "<br/>";
           
$msg .= 'Caption : ' . $media->getCaption() . "<br/>";
           
$msg .= 'Link : ' . $media->getLink() . "<br/>";
           
$msg .= 'Instructions: ' . $instruction . "<br/>";
           
$msg .= '============================' . "<br/>";
            echo
$msg;

           
$postId = explode('/', $media->getLink());

            if (!
$checkPost->postIsExisted($postId[4])) {
               
SendMail::sendMail($msg, $media, $feed->getUserName());
               
$checkPost->insertPostId($postId[4]);
            }

            break;
        }

       
$msg = wordwrap($msg, 70);

       
// Second Page

       
$api->setEndCursor($feed->getEndCursor());

       
sleep(1); // avoir 429 Rate limit from Instagram

       
$feed = $api->getFeed();

        echo
"<br/><br/>";
        echo
'============================' . "<br/>";
        echo
'Medias second page : ' . "<br/>";
        echo
'============================' . "<br/><br/>";

       
/** @var \Instagram\Hydrator\Component\Media $media */
       
foreach ($feed->getMedias() as $media) {
            echo
'ID : ' . $media->getId() . "<br/>";
            echo
'Caption : ' . $media->getCaption() . "<br/>";
            echo
'Link : ' . $media->getLink() . "<br/>";
            echo
'Instructions: ' . $instruction . "<br/>";
            echo
'============================' . "<br/>";
        }

       
// And etc...

   
} catch (\Instagram\Exception\InstagramException $exception) {
       
var_dump($exception->getMessage());
    }
}


Details

ig-feed-notification

Introduction

This is the simple web service and it can send the latest Instagram feed with specific user via SMTP server.

Requirements

  • php>=5.6
  • Composer
  • SMTP server
  • MySQL/MariaDB

Usage

  • Clone the repository.
git clone https://github.com/peter279k/ig-feed-notification

  • Download composer and install the required dependencies.
php composer.phar install -n

  • Copy the `.env.example` to `.env` and set the DB host, driver, database name, user name, user password, mail host, user name and password.
cp .env.example .env

  • Copy the `phinx.yml.example` to `phinx.yml` and remember to set the database name, user name and password in the production block.
cp phinx.yml.example phinx.yml

  • Execute the database migration in the project root path.
php vendor/bin/phinx migrate

  • Visit the `index.php` via the web browser.
http://host-name-or-ip-address/ig-feed-notification/index.php

  • That's all. Enjoy it!

  Files folder image Files  
File Role Description
Files folder imagedb (1 directory)
Files folder imagesrc (2 files)
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file phinx.yml.example Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  db  
File Role Description
Files folder imagemigrations (1 file)

  Files folder image Files  /  db  /  migrations  
File Role Description
  Plain text file 20180805152948_initial_post_record.php Class Class source

  Files folder image Files  /  src  
File Role Description
  Plain text file CheckIgPost.php Class Class source
  Plain text file SendMail.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:49
This week:1
All time:10,667
This week:560Up