This is an unofficial SDK for the Instagram Private API in PHP
I decided to build this because most libraries for the Instagram Private API I have come across aren't OOP based and are difficult to use.
If you like this project, please consider donating towards my coffee addiction fund, so I can continue to push commits!
- Paypal: Donate
- Bitcoin: 1814x9kioBxPDBCQx8oaty7e6Z3DAosucd
composer require liamcottle/instagram-sdk-php
require("../vendor/autoload.php");
$instagram = new \Instagram\Instagram();
If you want to test code that is in the master branch, which hasn't been pushed as a release, you can use dev-master
.
composer require liamcottle/instagram-sdk-php dev-master
What?! Grab it here: https://getcomposer.org/
Examples can be seen in the examples folder.
Read: Session Management, to avoid calling login
in each script.
$instagram->login("username", "password");
$maxId
:string
(Optional) Used for Pagination
$instagram->getTimelineFeed($maxId);
$userId
:string|User
User or User Id to get Feed of$maxId
:string
(Optional) Used for Pagination
$instagram->getUserFeed($userId, $maxId);
$maxId
:string
(Optional) Used for Pagination
$instagram->getMyUserFeed($maxId);
$maxId
:string
(Optional) Used for Pagination
$instagram->getLikedFeed($maxId);
$tag
:string
Tag$maxId
:string
(Optional) Used for Pagination
$instagram->getTagFeed($tag, $maxId);
$locationId
:string|Location
Location or Location Id to get Feed of$maxId
:string
(Optional) Used for Pagination
$instagram->getLocationFeed($locationId, $maxId);
$userId
:string|User
User of User Id to get Tags Feed of$maxId
:string
(Optional) Used for Pagination
$instagram->getUserTagsFeed($userId, $maxId);
$mediaId
:string|FeedItem
FeedItem or FeedItem Id to Like
$instagram->likeMedia($mediaId);
$mediaId
:string|FeedItem
FeedItem or FeedItem Id to Unlike
$instagram->unlikeMedia($mediaId);
$mediaId
:string|FeedItem
FeedItem or FeedItem Id to Delete$mediaType
:int
Media Type (Constants available inDeleteMediaRequest
class)
$instagram->deleteMedia($mediaId, $mediaType);
$mediaId
:string|FeedItem
FeedItem or FeedItem Id to Comment on$comment
:string
Comment
$instagram->commentOnMedia($mediaId, $comment);
$mediaId
:string|FeedItem
FeedItem or FeedItem Id of Media to get Comments from$maxId
:string
(Optional) Used for Pagination
$instagram->getMediaComments($mediaId, $maxId);
$mediaId
:string|FeedItem
FeedItem or FeedItem Id to Delete Comments from$commentIds
:array
Comment Ids to Delete
$instagram->deleteCommentsFromMedia($mediaId, $commentIds);
$userId
:string|User
User or User Id to get Info of
$instagram->getUserInfo($userId);
$userId
:string|User
User or User Id to get Followers of$maxId
:string
(Optional) Used for Pagination
$instagram->getUserFollowers($userId, $maxId);
$userId
:string|User
User or User Id to get Following of$maxId
:string
(Optional) Used for Pagination
$instagram->getUserFollowing($userId, $maxId);
$userId
:string|User
User or User Id to get GeoMedia of
$instagram->getUserMap($userId);
$mediaId
:string|FeedItem
FeedItem or FeedItem Id to get Info of
$instagram->getMediaInfo($mediaId);
$instagram->getCurrentUserAccount();
$firstname
:string
First Name$email
:string
Email$phoneNumber
:string
Phone Number$gender
:int
Gender (Constants available inUser
class)$biography
:string
: Biography$externalUrl
:string
External Url
$instagram->editUserProfile($firstname, $email, $phoneNumber, $gender, $biography, $externalUrl);
$instagram->setAccountPublic();
$instagram->setAccountPrivate();
$userId
:string|User
User or User Id to show Friendship between
$instagram->showFriendship($userId);
$userId
:string|User
User or User Id to Follow
$instagram->followUser($userId);
$userId
:string|User
User or User Id to Unfollow
$instagram->unfollowUser($userId);
$userId
:string|User
User or User Id to Block
$instagram->blockUser($userId);
$userId
:string|User
User or User Id to Unblock
$instagram->unblockUser($userId);
$query
:string
Tag to Search for
$instagram->searchTags($query);
$query
:string
User to Search for
$instagram->searchUsers($query);
$query
:string
Place to Search for
$instagram->searchFacebookPlaces($query);
$latitude
:string
Latitude$longitude
:string
Longitude
$instagram->searchFacebookPlacesByLocation($latitude, $longitude);
$path
:string
File path of Profile Picture to Upload
$instagram->changeProfilePicture($path);
$instagram->removeProfilePicture();
$path
:string
File path of Photo to Post$caption
:string
Caption for this Photo
$instagram->postPhoto($path, $caption);
$mediaId
:string|FeedItem
FeedItem or FeedItem Id to Edit$caption
:string
Caption for this Media
$instagram->editMedia($mediaId, $caption);
$username
:string
Username to find User by
$instagram->getUserByUsername($username);
$instagram->logout();
To avoid logging in each time, you can use the saveSession
and initFromSavedSession
methods.
Script 1:
//Login
$instagram->login("username", "password");
//Serialize the Session into a JSON string
$savedSession = $instagram->saveSession();
//Store $savedSession in Database, or Cookie etc
Script 2:
//Load $savedSession from Database or Cookie etc
$savedSession = ...;
//Init from Saved Session
$instagram->initFromSavedSession($savedSession);
//Session is Restored, do something!
$instagram-> ...;
Some Instagram endpoints return paginated data.
To access the next page of data, you will need to get the next maximum ID from the response object and pass it into the same method as the nextMaxId
parameter.
Example:
//Get TimelineFeed
$timelineFeed = $instagram->getTimelineFeed();
//This will be null if there are no more pages.
$nextMaxId = $timelineFeed->getNextMaxId();
//We have another page of Items
if($nextMaxId != null){
//Get the next page.
$timelineFeed = $instagram->getTimelineFeed($nextMaxId);
}
Use a Proxy between your Server and the Instagram API
$instagram->setProxy("127.0.0.1:8888");
Optional Username/Password Authentication
$instagram->setProxy("127.0.0.1:8888", "proxyUsername", "proxyPassword");
Enable or Disable Peer Verification, for testing with Charles Proxy etc.
$instagram->setVerifyPeer(false);
- Inbox
- Direct Share
- Recent Activity
- Register new Accounts
- Upload and Post Videos
If you would like to contribute to this project, please feel free to submit a pull request.
Before you do, take a look at the issues to see if the functionality you want to contribute to is already in development.
MIT
The name "Instagram" is a copyright of Instagram, Inc.
This project is in no way affiliated with, authorized, maintained, sponsored or endorsed by Instagram, Inc or any of its affiliates or subsidiaries.
I, the project owner and creator, am not responsible for any legalities that may arise in the use of this project. Use at your own risk.