L
L
Ler Den2018-10-31 02:40:33
Node.js
Ler Den, 2018-10-31 02:40:33

How to read and serialize Instagram response?

I'm trying to get a list of followers using instagram-private-api . I did everything as in the example, we take data from Instagram on request to the NodeJS endpoint.

var randomString = 'mydeviceandroid';
var accountId = 'XXX';

var device = new Client.Device(randomString);
var storage = new Client.CookieFileStorage(__dirname + '/cookies/' + randomString + '.json');

router.get('/api/followers', function (request, response) {
    Client.Session.create(device, storage, process.env.USERNAME, process.env.PASSWORD)
        .then(function (session) {
            // Now you have a session, we can follow / unfollow, anything...
            var feed = new Client.Feed.AccountFollowers(session, accountId);
            return feed.get();
        })
        .then(function (data) {
            response.status(200).send({ data: data });
        });
});

In response, the data comes, but for some reason it is impossible to send it to the front - an error occurs in the NodeJS console
Unhandled rejection Error: store does not support getAllCookies and cannot be serialized

What's wrong with this answer from Instagram? This is not a regular json, here is an example of a single subscriber response.
Account {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  _session:
   Session {
     _device:
      Device {
        username: 'test',
        _md5int: 5456456,
        _api: 21,
        _release: '5.1.1',
        _dpi: '577',
        _resolution: '320x480',
        _info: [Object],
        _language: 'en_US' },
     _cookiesStore:
      CookieFileStorage {
        storage: { idx: { 'i.instagram.com':
   { '/':
      { rur: Cookie="rur=FTW; Path=/; Secure; HttpOnly; hostOnly=true; aAge=425ms; cAge=1543888ms",
        mid: Cookie="mid=xxx; Expires=Fri, 27 Oct 2028 22:59:13 GMT; Max-Age=315360000; Path=/; Secure; hostOnly=true; aAge=750ms; cAge=1543887ms",
        urlgen: Cookie="urlgen="{\"xxx\": xxx}:xxx-64"; Path=/; Secure; HttpOnly; hostOnly=true; aAge=425ms; cAge=1543887ms",
        mcd: Cookie="mcd=3; Expires=Fri, 27 Oct 2028 22:59:13 GMT; Max-Age=315360000; Path=/; Secure; hostOnly=true; aAge=750ms; cAge=1543887ms",
        csrftoken: Cookie="csrftoken=xxx; Expires=Tue, 29 Oct 2019 23:24:56 GMT; Max-Age=31449600; Path=/; Secure; hostOnly=true; aAge=424ms; cAge=1543887ms",
        ds_user: Cookie="ds_user=e.nordic14; Expires=Mon, 28 Jan 2019 22:59:52 GMT; Max-Age=7776000; Path=/; Secure; HttpOnly; hostOnly=true; aAge=750ms; cAge=1504497ms",
        shbid: Cookie="shbid=5375; Expires=Tue, 06 Nov 2018 22:59:52 GMT; Max-Age=604800; Path=/; Secure; HttpOnly; hostOnly=true; aAge=750ms; cAge=1504496ms",
        shbts: Cookie="shbts=xxx; Expires=Tue, 06 Nov 2018 22:59:52 GMT; Max-Age=604800; Path=/; Secure; HttpOnly; hostOnly=true; aAge=750ms; cAge=1504496ms",
        ds_user_id: Cookie="ds_user_id=7968036481; Expires=Mon, 28 Jan 2019 23:24:56 GMT; Max-Age=7776000; Path=/; Secure; hostOnly=true; aAge=425ms; cAge=1504494ms",
        sessionid: Cookie="sessionid=XXX; Expires=Wed, 30 Oct 2019 22:59:52 GMT; Max-Age=31536000; Path=/; Secure; HttpOnly; hostOnly=true; aAge=750ms; cAge=1504493ms",
        is_starred_enabled: Cookie="is_starred_enabled=yes; Expires=Fri, 27 Oct 2028 22:59:55 GMT; Max-Age=315360000; Path=/; Secure; HttpOnly; hostOnly=true; aAge=750ms; cAge=1502059ms",
        igfl: Cookie="igfl=e.nordic14; Expires=Wed, 31 Oct 2018 22:59:55 GMT; Max-Age=86400; Path=/; Secure; HttpOnly; hostOnly=true; aAge=750ms; cAge=1502059ms",
        ig_direct_region_hint: Cookie="ig_direct_region_hint=FRC; Expires=Tue, 06 Nov 2018 22:59:55 GMT; Max-Age=604800; Path=/; Secure; HttpOnly; hostOnly=true; aAge=750ms; cAge=1501300ms" } } } } },
     _jar: RequestJar { _jar: [Object] } },
  _params:
   { pk: xxx,
     username: 'xxx',
     fullName: 'xxx',
     isPrivate: false,
     profilePicUrl: 'XXX',
     profilePicId: 'XXX',
     isVerified: false,
     hasAnonymousProfilePicture: false,
     reelAutoArchive: 'on',
     picture: 'XXX',
     id: XXX},
  id: XXX}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2018-10-31
@opium

Send just a string

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question