pgrimaud / instagram-user-feed

This is a scrapper to easily fetch any feed and interact with Instagram (like, follow, etc.) without OAuth for PHP.
MIT License
881 stars 137 forks source link

Login multiple times on form with 2 steps #81

Closed manguon closed 4 years ago

manguon commented 4 years ago

Hi everybody,

I have a form with 2 steps as follows (on 2 pages):

Step 1: submit username with input field (the purpose is to check the existence of the username) Step 2: get the image from profile that submited above

Do I have to use the code below at every step?

$api-> login ($username, $password);

Is there any way to not have to log in multiple times?

Thank you so much

pgrimaud commented 4 years ago

Hello @vietel,

Yes you have to login each time you instantiate the package.

But, after the first login, session cookies are stored into cache driver. Then this data cached are used to each next Instagram calls. (https://github.com/pgrimaud/instagram-user-feed/blob/6.x/src/Instagram/Api.php#L60)

Do I have to use the code below at every step?

$api-> login ($username, $password);

Yes, but in fact, you really login to Instagram 1 time. (https://github.com/pgrimaud/instagram-user-feed/blob/6.x/src/Instagram/Api.php#L74, when cookies into cache driver are empty)

manguon commented 4 years ago

Thank you for the explanation,

In your opinion, should you set the time for session cookies or leave the default?

I mean: should I reset a session cookies after a specific time (eg.1 hour)?

pgrimaud commented 4 years ago

In your opinion, should you set the time for session cookies or leave the default?

Just to be clear, the instagram session is not shared with default PHP session. Instagram session is stored with cache driver.

The Instagram session is valid for... 1 YEAR. So in theory, using a cache driver and one account will trigger only one real login to Instagram then reusing session for a long time.

I used this package on one of my website, with a script which only retrieve new medias 4 times per day. The session stored in the cache driver (FS here) is the same since the 22nd of May 2020.

I mean: should I reset a session cookies after a specific time (eg.1 hour)?

Nope 😉

manguon commented 4 years ago

Thank you for the useful information.

Today I had another problem with the getLogin () function.

[02-Jul-2020 17:13:09 UTC] PHP Fatal error: Uncaught Error: Call to a member function getLogin () on boolean in /var/www/html/include/step-2.php:53

        try {
            $instagram = new Api($cachePool);
            $instagram->login($credentials->getLogin(), $credentials->getPassword());  --> LINE 53

(My instagram username and password are declared in credentials.php and it has been included )

Look forward to the help.

Thanks

pgrimaud commented 4 years ago

@vietel Weird...

You also could try this :

$instagram = new Api($cachePool);
$instagram->login('instagramLogin', 'instagramPassword');

The credentials.php file was an example using an anonymous class : fast way for example, not the best for production.

manguon commented 4 years ago

Thank you @pgrimaud