Giter Site home page Giter Site logo

instagram-api's Introduction

PHP7.2 Ready Latest Stable Version Latest Unstable Version Build Status License

Instagram Private API Library

To learn how to use this library, please refer to the source code as well as the examples.

Installation

You can install this library by using composer

composer require nicklasw/instagram-api

Features

  • Supports asynchronous and parallel requests
  • Easily extendable with new requests
  • Session and device management
  • Access discover feeds (channels, explore, top live)
  • Access direct feeds (inbox, thread)
  • Much more

Example

<?php

use Instagram\SDK\Instagram;

require_once 'vendor/autoload.php';

$instagram = Instagram::builder()->build();
$instagram->login('INSERT_USERNAME', 'INSERT_PASSWORD');

$response = $instagram->inbox();

foreach ($response->getInbox()->getThreads() as $thread) {
    $thread->sendMessage("Hello");
}

Changelog

Please see the changelog for a release history and indications on how to upgrade from one version to another.

Contributing

If you find any problems or have suggestions about this crate, please submit an issue. Moreover, any pull request, code review and feedback are welcome.

Code Guide

We use GitHub Actions to make sure the codebase is consistent (composer run lint-fix && composer run code-analyze). We try to keep comments at a maximum of 160 characters of length and code at 120.

License

MIT

instagram-api's People

Contributors

chhaihongsrun avatar deegital avatar dependabot[bot] avatar erfanbahramali avatar gpibarra avatar mohammad-rj avatar nicklaswallgren avatar pourydev avatar ryanopily avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

instagram-api's Issues

Followers Number

Hey

Is it possible to get the followers (and following) number? I saw that on the getUser() we get this:
followerCount:Instagram\SDK\Response\DTO\General\User:private

But it's private and I can't access it.

Any plans for supporting endpoints to retrieve followers/following lists?

As far as I can see there's no support for followers/following in the library.. are there any plans to support this data?

I'd be open to working it out and submitting a PR but I really don't know where to start in terms of how you're determining the endpoints and parameters to them that are required.

Feed API not working anymore

It seems that the API to get the feed by the user is not working anymore.
This is the response that I get from the Guzzle client.
I saw that the new API could be something like /users/USERNAME/media/recent/
I didn't go deeper in this issue, did you?

Client error: `POST https://i.instagram.com/api/v1/feed/user/USERNAME/` resulted in a `404 Not Found` response:
<!DOCTYPE html>
<html lang="en" class="no-js logged-in client-root touch">
    <head>
        <meta charset="utf-8">
    (truncated...)

Parse error: syntax error ...

I'm trying to use this API but I get this error from API's self codes.
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /opt/lampp/htdocs/vendor/symfony/deprecation-contracts/function.php on line 23
How can I fix this problem?

Thanks

searchByHashtag

$instagram->searchByHashtag('dog'); only leaves me with a fatal error and so does a couple of other traits such as searchByUser and feedByHashtag etc...

Fatal error: Uncaught Instagram\SDK\Responses\Exceptions\ApiResponseException in /api/exp/vendor/nicklasw/instagram-api/src/Responses/Serializers/AbstractSerializer.php:99 Stack trace: #0 /api/exp/vendor/nicklasw/instagram-api/src/Responses/Serializers/AbstractSerializer.php(50): Instagram\SDK\Responses\Serializers\AbstractSerializer->handleInvalidHttpResponse() #1 /api/exp/vendor/nicklasw/instagram-api/src/Requests/Traits/RequestMethods.php(216): Instagram\SDK\Responses\Serializers\AbstractSerializer->decode() #2 /api/exp/vendor/nicklasw/instagram-api/src/Support/Promises/functions.php(36): Instagram\SDK\Requests\GenericRequest->Instagram\SDK\Requests\Traits{closure}() #3 /api/exp/vendor/guzzlehttp/promises/src/TaskQueue.php(48): Instagram\SDK\Support\Promises{closure}() #4 /api/exp/vendor/nicklasw/instagram-api/src/Http/Guzzle/Handlers/CurlMultiHa in /api/exp/vendor/nicklasw/instagram-api/src/Responses/Serializers/AbstractSerializer.php on line 99

Messanger

Hi! It's a good library. I want to implement it in our company's CRM system. But I didn't figure out how to use it as a messenger. For example, to receive a list of dialogs, messages of these dialogs. Send messages. Please tell me, is it possible? How can this be implemented? Thanks!

Get the whole conversation on inbox

hey, can we get the whole conversation on inbox?
i try to debug the $envelope->getInbox(); and i just see the last conversation, so when there is 2 conversation on each thread, i only see the last one, the first one didn't show up..
thanks,

one more thing, i couldn't get any example to implement sendText() method, i want to try sending a direct message to user, any help would be appreciated.. thanks

following list max 50

When I pull the list I follow, it draws a maximum of 50 people, but my list is 180 people, how can I solve this problem?
The list I follow is not working properly.

Return list of photos by hash tag.

Return list of photos by hash tag.

IG used to allow this via their API but then removed it. If you can add this I'll give it a go on my works website to replace that functionality.

Thanks.

error

Fatal error: Uncaught Instagram\SDK\Exceptions\UnexpectedResponseException: Retrieved unexpected response {"message":"Sorry, there was a problem with your request.","status":"fail"} in /var/www/abdox/data/www/9k.uz/vendor/nicklasw/instagram-api/src/Response/Serializers/AbstractResponseSerializer.php:103 Stack trace: #0 /var/www/abdox/data/www/9k.uz/vendor/nicklasw/instagram-api/src/Response/Serializers/AbstractResponseSerializer.php(47): Instagram\SDK\Response\Serializers\AbstractResponseSerializer::handleUnexpectedHttpResponse(Object(GuzzleHttp\Psr7\Response)) #1 /var/www/abdox/data/www/9k.uz/vendor/nicklasw/instagram-api/src/Response/Serializers/User/LoginResponseSerializer.php(59): Instagram\SDK\Response\Serializers\AbstractResponseSerializer->decode(Object(GuzzleHttp\Psr7\Response), Object(Instagram\SDK\Client\Client)) #2 /var/www/abdox/data/www/9k.uz/vendor/nicklasw/instagram-api/src/Client/Client.php(176): Instagram\SDK\Response\Serializers\User\LoginResponseSerializer->decode(Object(GuzzleHttp\Psr7\Response), Object(Instagram\SDK\Client\Client)) #3 /var/www/abdox/data/www/9k.uz/vendor/nicklasw/instagram-api/src/Utils/PromiseUtils.php(34): Instagram\SDK\Client\Client->Instagram\SDK\Client{closure}() #4 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/promises/src/TaskQueue.php(52): Instagram\SDK\Utils\PromiseUtils::Instagram\SDK\Utils{closure}() #5 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(159): GuzzleHttp\Promise\TaskQueue->run() #6 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(185): GuzzleHttp\Handler\CurlMultiHandler->tick() #7 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Handler\CurlMultiHandler->execute(true) #8 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn() #9 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending() #10 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList() #11 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending() #12 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList() #13 /var/www/abdox/data/www/9k.uz/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending() #14 /var/www/abdox/data/www/9k.uz/vendor/nicklasw/instagram-api/src/Utils/PromiseUtils.php(54): GuzzleHttp\Promise\Promise->wait() #15 /var/www/abdox/data/www/9k.uz/vendor/nicklasw/instagram-api/src/Traits/MakeAccountRequestAccessible.php(33): Instagram\SDK\Utils\PromiseUtils::wait(Object(GuzzleHttp\Promise\Promise)) #16 /var/www/abdox/data/www/9k.uz/mm.php(8): Instagram\SDK\Instagram->login('ddddddddd', 'ddddddddd') #17 {main} thrown in /var/www/abdox/data/www/9k.uz/vendor/nicklasw/instagram-api/src/Response/Serializers/AbstractResponseSerializer.php on line 103

Error

Fatal error: Uncaught TypeError: Return value of Instagram\SDK\DTO\General\User::getId() must be of the type integer, float returned in C:\xampp\vendor\nicklasw\instagram-api\src\DTO\General\User.php:62
Stack trace:
#0 C:\xampp\vendor\nicklasw\instagram-api\src\DTO\Direct\Thread.php(560): Instagram\SDK\DTO\General\User->getId()
#1 C:\xampp\vendor\nicklasw\instagram-api\src\Responses\Serializers\Traits\OnPropagateDecodeEventTrait.php(45): Instagram\SDK\DTO\Direct\Thread->onDecodeUsers()
#2 C:\xampp\vendor\nicklasw\instagram-api\src\DTO\Direct\Thread.php(550): Instagram\SDK\DTO\Direct\Thread->propagate(Array)
#3 C:\xampp\vendor\nicklasw\instagram-api\src\Responses\Serializers\Traits\OnPropagateDecodeEventTrait.php(71): Instagram\SDK\DTO\Direct\Thread->onDecode(Array, Array)
#4 C:\xampp\vendor\nicklasw\instagram-api\src\Responses\Serializers\Traits\OnPropagateDecodeEventTrait.php(48): Instagram\SDK\DTO\Direct\Inbox->invokeDecodeEventListener(Array, Array)
#5 C:\xampp\vendor\nicklasw\instagram-api\src\DTO\Direct\Inbox.php(129 in C:\xampp\vendor\nicklasw\instagram-api\src\DTO\General\User.php on line 62

Proxy type.

I was testing the api and I was wondering what is the supported proxy type, I've tested some and all failed.

get pending inbox

hi. how i get pending inbox and confirm then?
and
How to mark the thread read?

how get user media(post) count

i get this response with trying getUser(), i need count post of user.
how can get that? i can feed by user and loop until end and counting media but this is a bad solution, is there any other way ?

Instagram\SDK\Response\Responses\Users\UserInformationResponse Object
(
    [user:Instagram\SDK\Response\Responses\Users\UserInformationResponse:private] => Instagram\SDK\Response\DTO\General\User Object
        (
            [id:Instagram\SDK\Response\DTO\General\User:private] => 7431104989
            [username:Instagram\SDK\Response\DTO\General\User:private] => krammpus_nacht
            [fullName:Instagram\SDK\Response\DTO\General\User:private] => Krammpus Nacht
            [isPrivate:Instagram\SDK\Response\DTO\General\User:private] =>
            [profilePictureUrl:Instagram\SDK\Response\DTO\General\User:private] =>
            [friendshipStatus:Instagram\SDK\Response\DTO\General\User:private] =>
            [isVerified:Instagram\SDK\Response\DTO\General\User:private] =>
            [hasAnonymousProfilePicture:Instagram\SDK\Response\DTO\General\User:private] =>
            [followerCount:Instagram\SDK\Response\DTO\General\User:private] => 908
            [followingCount:Instagram\SDK\Response\DTO\General\User:private] => 475
            [client:Instagram\SDK\Response\DTO\General\User:private] => Instagram\SDK\Client\Client Object
                (
                )

        )

    [client:Instagram\SDK\Response\Responses\Users\UserInformationResponse:private] => Instagram\SDK\Client\Client Object
        (
        )

    [status:protected] => ok
    [errorType:protected] =>
    [message:protected] =>
    [invalidCredentials:protected] =>
)

getProfilePictureUrl

Hi @NicklasWallgren ,

it seems that getProfilePictureUrl doesn't work..I mean anything related to profile pictures returns null even if profile is public.
Is that some new Instagram restriction? If not I can try to fix it, just point me in right direction.

Thanks.

404 on Feed

Getting 404's on the feed functions

This function:

  $feed = $instagram->feedByHashtag($hashtag);
  $items = $feed->getItems();

Url formatted here seems to have been changed.

case TYPE_HASHTAG:
$result = $this->queryFeed($type, 'feed/tag/%s/', $query, $maxId);
 break;

In case someone has an idea, would appreciate. Been debugging a bit, but didn't find anything yet online. Seems to be an unofficial api.

Tried several instagram logins.

Uncaught Instagram\SDK\Exceptions\ApiResponseException in src/Response/Serializers/AbstractResponseSerializer.php:137

i cannot login to instagrame


--   | Fatal error: Uncaught Instagram\SDK\Exceptions\ApiResponseException in /www/wwwroot/8851/src/Response/Serializers/AbstractResponseSerializer.php:137   | Stack trace:   | #0 /www/wwwroot/8851/src/Response/Serializers/AbstractResponseSerializer.php(59): Instagram\SDK\Response\Serializers\AbstractResponseSerializer::toException()   | #1 /www/wwwroot/8851/src/Response/Serializers/User/LoginResponseSerializer.php(59): Instagram\SDK\Response\Serializers\AbstractResponseSerializer->decode()   | #2 /www/wwwroot/8851/src/Client/Client.php(177): Instagram\SDK\Response\Serializers\User\LoginResponseSerializer->decode()   | #3 /www/wwwroot/8851/src/Utils/PromiseUtils.php(34): Instagram\SDK\Client\Client->Instagram\SDK\Client\{closure}()   | #4 /www/wwwroot/8851/vendor/guzzlehttp/promises/src/TaskQueue.php(48): Instagram\SDK\Utils\PromiseUtils::Instagram\SDK\Utils\{closure}()   | #5 /www/wwwroot/8851/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(118): GuzzleHttp\Promise\TaskQueue->run()   | #6 /www/wwwroot/8851/vendor/guzzlehttp/guzzle/src/Handler/CurlMu in /www/wwwroot/8851/src/Response/Serializers/AbstractResponseSerializer.php on line 137

How can I comment on other's media post?

I executed this code.

$instagram = Instagram::builder()->build();
$instagram->login('id', 'pw');
$response = $instagram->comment('media_id', 'test');

But I got this error.

 Instagram\SDK\Exceptions\ApiResponseException  : feedback_required

  at /vagrant/app/adtech_ugc/vendor/nicklasw/instagram-api/src/Response/Serializers/AbstractResponseSerializer.php:137
    133|             case ResponseErrorTypes::RATE_LIMIT:
    134|                 $exception = new RateLimitResponseException($envelope);
    135|                 break;
    136|             default:
  > 137|                 $exception = new ApiResponseException($envelope);
    138|                 break;
    139|         }
    140|
    141|         return $exception;

  Exception trace:

  1   Instagram\SDK\Response\Serializers\AbstractResponseSerializer::toException(Object(Instagram\SDK\Response\Responses\Media\CommentResponse))
      /vagrant/app/adtech_ugc/vendor/nicklasw/instagram-api/src/Response/Serializers/AbstractResponseSerializer.php:59

  2   Instagram\SDK\Response\Serializers\AbstractResponseSerializer::decode(Object(GuzzleHttp\Psr7\Response), Object(Instagram\SDK\Client\Client))
      /vagrant/app/adtech_ugc/vendor/nicklasw/instagram-api/src/Client/Client.php:174

Please tell me how to write the correct code.
Thank you for the wonderful product!

The promise was rejected with reason: The path of a URI with an authority must start with a slash &quot;/&quot; or be empty

Hi,
I'm having an issue after a fresh install with the authenticate_using_password example.

**Fatal error**: Uncaught Instagram\SDK\Exceptions\InstagramException: The promise was rejected with reason: The path of a URI with an authority must start with a slash "/" or be empty in /vendor/nicklasw/instagram-api/src/Utils/PromiseUtils.php:58 
Stack trace: 
#0 /vendor/nicklasw/instagram-api/src/Traits/MakeAccountRequestAccessible.php(33): Instagram\SDK\Utils\PromiseUtils::wait(Object(GuzzleHttp\Promise\Promise)) 
#1 /index.php(9): Instagram\SDK\Instagram->login('XXXXXXXX', 'XXXXXXXX') 
#2 {main} thrown in /vendor/nicklasw/instagram-api/src/Utils/PromiseUtils.php on line 58

Am I missing something ?

Install without composer?

Is it possible to use this library without the composer?
Download the files and just load them somehow?

Get user info by username

Hi ı just trying to get spesicified users profile picture and full name by username.

I searched everywhere but ı did not find anything about it.

Can anyone help me please

about getting proper output

hello i have just discovered the api and I am thinking of using it. but the output I received is very mixed. how can I print this in a smoother array format. or how I can use the data I receive. here is a section of the data I received.

Instagram\SDK\Response\Responses\Feed\FeedResponse Object ( [status:protected] => ok [errorType:protected] => [message:protected] => [invalidCredentials:protected] => [client:Instagram\SDK\Response\Responses\Feed\FeedResponse:private] => Instagram\SDK\Client\Client Object ( ) [rankedItems:Instagram\SDK\Response\Responses\Feed\FeedResponse:private] => Array ( ) [items:Instagram\SDK\Response\Responses\Feed\FeedResponse:private] => Array ( [0] => Instagram\SDK\Response\DTO\Hashtag\Item Object ( [pk:Instagram\SDK\Response\DTO\Hashtag\Item:private] =>

Loop Through Objects?

Hello,
Sorry for the stupid question, but I'm no expert in PHP, how can I loop the users in the $followersResponse ,$followingResponse variables?
I want to go through each one of the users and count their followers and followings count.

$userResponse = $instagram->userByName('dogsofinstagram');
$followersResponse = $userResponse->getUser()->followers();
$followingResponse = $instagram->following($userResponse->getUser()->getId());

thanks!

Auth using access token

@NicklasWallgren is it possible to authenticate using access token? I can get access token in separate process. As I can see at the moment only way to auth is user and pass, that can be security issue or trust issue as users are mostly using oauth with that kind of apps. Thanks

guzzlehttp/guzzle ^6.2 conflicts with Laravel 8 requires guzzlehttp/guzzle ^7.0.1

Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires nicklasw/instagram-api ^0.10.0 -> satisfiable by nicklasw/instagram-api[v0.10.0].
- nicklasw/instagram-api v0.10.0 requires guzzlehttp/guzzle ^6.2 -> found guzzlehttp/guzzle[6.2.0, ..., 6.5.x-dev] but it conflicts with your root composer.json require (^7.0.1).

Please, package to support multiple guzzlehttp/guzzle.

  • I don't other way to fix it, I make it work by downloading it then load it locally by changing the composer.json: "guzzlehttp/guzzle": "^6.2|^7.0.1",

I couldnt get to run any of the examples .

Fatal error: Uncaught TypeError: Return value of Instagram\SDK\DTO\Direct\ThreadItem::getUserId() must be of the type integer, float returned in C:\xampp\vendor\nicklasw\instagram-api\src\DTO\Direct\ThreadItem.php:77
Stack trace:
#0 C:\xampp\vendor\nicklasw\instagram-api\src\Responses\Serializers\Traits\OnPropagateDecodeEventTrait.php(199): Instagram\SDK\DTO\Direct\ThreadItem->getUserId()
#1 C:\xampp\vendor\nicklasw\instagram-api\src\Responses\Serializers\Traits\OnPropagateDecodeEventTrait.php(173): Instagram\SDK\DTO\Direct\Thread->getRequirementParameterValue(Object(Instagram\SDK\DTO\Direct\ThreadItem), 'userId')
#2 [internal function]: Instagram\SDK\DTO\Direct\Thread->Instagram\SDK\Responses\Serializers\Traits{closure}('userId')
#3 C:\xampp\vendor\nicklasw\instagram-api\src\Responses\Serializers\Traits\OnPropagateDecodeEventTrait.php(174): array_map(Object(Closure), Array)
#4 C:\xampp\vendor\nicklasw\instagram-api\src\Responses\Serializers\Traits\OnPropagateDecodeEventTrait.php(144): Instagram\SDK\DTO\Direct\Thread->ge in C:\xampp\vendor\nicklasw\instagram-api\src\DTO\Direct\ThreadItem.php on line 77

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.