Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Found this error when use getTopMediasByTag() and getMediasByTag(). Caching user session #76

Closed
javagose opened this issue Mar 19, 2017 · 10 comments
Assignees
Labels

Comments

@javagose
Copy link

After several request (5 request or more) i get this error:

Catchable fatal error: Object of class stdClass could not be converted to string in
C:\xampp\htdocs\instagram\vendor\raiym\instagram-php-scraper\src\InstagramScraper\Instagram.php
on line 519

@jonahfuller
Copy link

Getting the same error... dumping the $response var seems to be a security check from instagram... to verify that you are logging in to your account... Not sure the way around this

@raiym raiym self-assigned this Mar 20, 2017
@raiym raiym added the fixed label Mar 20, 2017
@raiym
Copy link
Member

raiym commented Mar 20, 2017

@javagose and @jonahfuller
thank you for comments

4682e97

Could you please check how new version works for you?
I have added session caching. For caching purpose I use this library: https://github.com/PHPSocialNetwork/phpfastcache

You don't need to change your code.
But you can specify where to store cache (otherwise it will be stored somewhere in /vendor folder).
If you want specify session cache folder:

$instagram = Instagram::withCredentials('PASTE_LOGIN', 'PASTE_PASSWORD', '/path/to/folder/');
$instagram->login();

And you need call $instagram->login() only once after creating object. It will check for existing session for specified username.
If cache file exists it will call instagram.com to check if session is not expired. In all other cases (session file is not exists, session expired) it will login again.

This issue will be open until I implement following:

  • In every function we need to check if session expired.
  • If session expired library should try to login and continue
  • If password is wrong it should throw corresponding exception

NOTE: Library does not track API limits, so you need adjust request frequency on your own

@raiym raiym changed the title Found this error when use getTopMediasByTag() and getMediasByTag() Found this error when use getTopMediasByTag() and getMediasByTag(). Caching user session Mar 20, 2017
@jonahfuller
Copy link

So far so good... I'll update if I find any issues. Thanks again for your continued work on this... Library is just what I needed to build my hashtaged photos wall.

@pinotarantino
Copy link

Hello Raym and thank you for your job!
I had the same issue, I followed your instruction (updated your version to 0.5.3 with composer; added the path for the cache) but I get the same error.
This happens with php 7.1 and centOS 7 (if this could help you).
Thank you again!
P;)

@raiym
Copy link
Member

raiym commented Mar 24, 2017

@pinotarantino strange.
Can you please give more info about your situation.

What exactly you do? (How many requests you send, how frequently, what is delay time)

@pinotarantino
Copy link

Hello Raiym,
this issue happens immediatly, at the first request of top media by tags.
The issue happens with 'use phpFastCache\CacheManager' or without it.
Note that I've the problem of SSL certificate, issue #63 (if this could matter).

Here you are an extract of my code, if this could help you:

"...
require '/root/vendor/autoload.php';

use phpFastCache\CacheManager;

Unirest\Request::verifyPeer(false);

use InstagramScraper\Instagram ;

$instagram = Instagram::withCredentials('pxxxxxx', 'pxxxxxxx', '/var/www/html/socialtool');
$instagram->login();
...
$medias_top = Instagram::getTopMediasByTagName("$kw");
..."

Thanks a lot!
P;)

@pinotarantino
Copy link

A clarification about SSL: I noticed now that with centOS, if I don't use 'Unirest\Request::verifyPeer(false)', it woks fine. I had the error of issue #63 in a previous project version developed on WAMP server. With Linux/Lamp the problem off SSL doesn't occur.

Thaks
P;)

@pinotarantino
Copy link

Problem solved if I make the call from the same IP I used when I registered my account on Istagram...;)

@javagose
Copy link
Author

javagose commented Apr 4, 2017

i still get the same error

Object of class stdClass could not be converted to string in
C:\xampp\htdocs\instascrapper\vendor\raiym\instagram-php-scraper\src\InstagramScraper\Instagram.php on line
525

what i'm trying to build is a website that let users scrapp instagram content, so i build different php files, each file is calling a different Instagram.php Method.

for example, getTopMediasByTag.php call getTopMediasByTag(tags), getUserMedias.php calls getMedias(username), getUser.php call getAccount(username) ... etc

In each file i use

$instagram = Instagram::withCredentials('PASTE_LOGIN', 'PASTE_PASSWORD', '/path/to/folder/');
$instagram->login();

@peyvand
Copy link

peyvand commented Apr 6, 2019

require('autoload.php');

use InstagramScraper\Instagram;
Unirest\Request::verifyPeer(false);

$instagram = Instagram::withCredentials('username', 'password', '/cached');
$instagram->login();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants