Instagram-private-api: Unhandled rejection CookieNotValidError

Created on 29 Jul 2016  路  4Comments  路  Source: dilame/instagram-private-api

I am using a newly created Instagram account I created for testing and I am receiving the following message:
Unhandled rejection CookieNotValidError: Cookiesessionidyou are searching found was either not found or not valid!

However, I was able to gain a session with an older Instagram account over two years old. When I remove theusername.json file from the cookies directory and try to gain a new session with the older account, I receive the same message Unhandled rejection CookieNotValidError: Cookiesessionidyou are searching found was either not found or not valid!

Any clues to the cause? Looking forward to working with this library. Thanks!

All 4 comments

@m-r-m-s when do you receiving following message? can you provide piece of code, what do you exactly doing? the message occurs when sessionid property is not availabe in .json cookie file.

@huttarichard When I run the code below, this is what generates the error. In my cookies directory, I have a accountname.json file. When I execute the code below, I see that it is populating the accountname.json file. I can share that json file as well if needed.

var Client = require('instagram-private-api').Client.V1;
var device = new Client.Device('SAMSUNG_GALAXY_S2', 'accountname');
var cookiePath = __dirname + '/cookies/accountname.json';
// Either gain already gained session
var session = new Client.Session(device, cookiePath);
// Or go for login
var promise = Client.Session.create(device, cookiePath, 'accountname', 'password');

promise.then(function(sessionInstance) {
   // Now you have session, do what ever private API allows
});

Client.Account.searchForUser(session, 'instagram')
    .then(function(accountInstance) {
        // accountInstance instanceof Client.Account -> true
        // accountInstance instanceof Client.Resource -> true
        console.log(accountInstance.id)
        // -> 1213.....
        console.log(accountInstance.params)
        // -> {username: 'instagram', picture: ....}

    })

@huttarichard I was able to gain a session! When getting the previous error, I was deleting the old accountname.json file, trying to gain a new session with no success with the same file name (accountname.json).
So, instead of deleting previous accountname.json and trying with the same json filename, I tried new_accountname.json and it worked!

this is promised based library. The example you provide is incorrect.

var Client = require('instagram-private-api').Client.V1;
var device = new Client.Device('SAMSUNG_GALAXY_S2', 'accountname');
var cookiePath = __dirname + '/cookies/accountname.json';
var promise = Client.Session.create(device, cookiePath, 'accountname', 'password');

promise.then(function(sessionInstance) {
   // you need to wait until session is available.Then you can use session to work with instagram.
   return Client.Account.searchForUser(session, 'instagram');
}).then(function(accountInstance) {
    console.log(accountInstance.id)
    console.log(accountInstance.params)
})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MMrR0b0TT picture MMrR0b0TT  路  18Comments

ambross picture ambross  路  10Comments

codingzombies picture codingzombies  路  19Comments

LouenLeoncoeur picture LouenLeoncoeur  路  12Comments

endquote picture endquote  路  12Comments