Unofficial Instagram API Client for PHP

Maintainers

Package info

github.com/alirezaprogrammermaker/uninsta

pkg:composer/alirezaprogrammermaker/uninsta

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2025-12-18 19:14 UTC

This package is auto-updated.

Last update: 2026-03-28 12:32:49 UTC


README

PHP Version License

A powerful and easy-to-use PHP library for interacting with Instagram's unofficial API.

Features

  • 🔐 Authentication: Login with session ID
  • 👤 User Management: Get user profiles, search users
  • 📸 Posts: Retrieve user posts with pagination
  • 📖 Stories: Access user stories
  • Highlights: Get user highlights
  • 💬 Comments & Likes: Retrieve post comments and likers
  • 🗂️ Session Management: Persistent session storage
  • 🔄 Clean Architecture: Well-organized, maintainable code

Installation

Install via Composer:

composer require alirezaprogrammermaker/uninsta

Quick Start

Basic Usage

use AlirezaProgrammerMaker\UnInsta\UnInsta;

// Initialize with session ID
$instagram = new UnInsta('your_session_id_here');

// Get current user
$currentUser = $instagram->getCurrentUser();
print_r($currentUser);

Login and Save Session

$instagram = new UnInsta();
$user = $instagram->loginWithSessionId('your_session_id');

if ($user) {
    echo "Logged in as: " . $user['username'];
}

Usage Examples

User Operations

// Get user by username
$user = $instagram->getUserByUsername('instagram');
echo $user['full_name'];

// Get user by ID
$user = $instagram->getUserById('25025320');

// Search users
$results = $instagram->searchUsers('cristiano');

Posts

// Get user posts (with pagination)
$posts = $instagram->getPosts('instagram', 12);

foreach ($posts['posts'] as $post) {
    echo $post['caption']['text'];
}

// Load more posts
if (isset($posts['max_id'])) {
    $morePosts = $instagram->getPosts('instagram', 12, $posts['max_id']);
}

// Get specific post
$post = $instagram->getPostById('media_id_here');

// Get post comments
$comments = $instagram->getPostComments('media_id_here');

// Get post likers
$likers = $instagram->getPostLikers('media_id_here');

Stories

// Get user stories
$stories = $instagram->getUserStories('user_id_here');

foreach ($stories as $story) {
    echo $story['taken_at'];
}

// Get multiple users' stories
$stories = $instagram->getMultipleStories(['user_id_1', 'user_id_2']);

Highlights

// Get user highlights
$highlights = $instagram->getUserHighlights('user_id_here');


// Get highlight media
$media = $instagram->getHighlightMedia('highlight_id_here');

Advanced Configuration

// With proxy
$instagram = new UnInsta(
    sessionId: 'your_session_id',
    cookies: [],
    proxy: 'http://proxy-server:port'
);

// Custom session storage path
$instagram->setSessionStoragePath('/custom/path/to/sessions');

Session Management

Sessions are automatically saved and can be reused:

use AlirezaProgrammerMaker\UnInsta\Session\SessionManager;

// Get session by username
$session = SessionManager::getByUsername('username');

// Get session by session ID
$session = SessionManager::getBySessionId('session_id');

// Delete session
SessionManager::delete('username');

// Get all sessions
$allSessions = SessionManager::all();

Architecture

The package is organized into logical components:

src/
├── Client/          # HTTP client implementation
├── Session/         # Session management
├── Api/             # API endpoints (User, Post, Story, Highlight)
├── Support/         # Helper classes (Constants, ResponseHandler)
├── Exceptions/      # Custom exceptions
└── UnInsta.php      # Main facade class

Error Handling

use AlirezaProgrammerMaker\UnInsta\Exceptions\ApiException;
use AlirezaProgrammerMaker\UnInsta\Exceptions\AuthenticationException;

try {
    $user = $instagram->getUserByUsername('nonexistent');
} catch (ApiException $e) {
    echo "API Error: " . $e->getMessage();
} catch (AuthenticationException $e) {
    echo "Auth Error: " . $e->getMessage();
}

Requirements

  • PHP >= 8.0
  • GuzzleHTTP ^7.0

Security Note

This is an unofficial Instagram API client. Use it responsibly and be aware of Instagram's terms of service. Session IDs should be kept secure and never shared publicly.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This project is not affiliated with, authorized, maintained, sponsored or endorsed by Instagram or any of its affiliates or subsidiaries. This is an independent and unofficial API client.

Support

If you encounter any issues or have questions, please open an issue on GitHub.