dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.99k stars 1.14k forks source link

Caption is null when uploading #966

Closed blaxbla123 closed 5 years ago

blaxbla123 commented 5 years ago

The post would successfully upload, but the captions would be empty: https://www.instagram.com/p/B4WQ0oQnVZs/.

Is it just me doing something wrong?

I've experienced this on 1.32.0 and 1.33.0 (was originally on 1.32.0, updated to 1.33.0 to see if that would resolve my issue). It happened out of the blue with my code about a day or two ago. I did some poking around and am consistently getting "caption: null" in the returned media object of "ig.publish.photo".

My code to test is:

(async() => {
     await loginIG();
     result = await ig.publish.photo({
          'file': createIMG(),
          'caption': 'hello hello'
     });
     console.log(result);
})();

// just for good measure, i'm including my login code as well
async function loginIG() {
     log.status('loginIG: logging in');

     let userFeed;
     let firstPageItems;

     profile = getFromStuff('.profile');
     const cookiesFile = getFromStuff('.cookies');

     if (cookiesFile !== undefined) {
          await ig.state.deserializeCookieJar(JSON.stringify(cookiesFile));
     }

     ig.state.generateDevice(username);

     if (profile !== undefined) {
          try {
               log.status('loginIG: test: getting user feed');
               userFeed = ig.feed.user(profile.pk);
               log.status('loginIG: test: getting items');
               firstPageItems = await userFeed.items();
               // eslint-disable-next-line eqeqeq
               if (userFeed == undefined || firstPageItems == undefined) {
                    throw new ErrorLoginIG.NullResponse();
               }
                    log.status(`loginIG: test: already logged in as: ${profile.username}!`);
          } catch (e) {
               log.status('loginIG: test: not already logged in! proceeding...');
               await tryToLogin();
          }
     } else {
          log.status('loginIG: test: not already logged in! proceeding...');
          await tryToLogin();
     }
     async function tryToLogin() {
          try {
               await ig.simulate.preLoginFlow();
               profile = await ig.account.login(username, password);
               await ig.simulate.postLoginFlow();

               writeToStuff('.cookies', await ig.state.serializeCookieJar());
               writeToStuff('.profile', profile);
               log.status(`loginIG: logged in as: ${profile.username}`);
               return;
          } catch (e2) {
               log.status(ig.state.checkpoint); // Checkpoint info here
               await ig.challenge.auto(true); // Requesting sms-code or click "It was me" button
               log.status(ig.state.checkpoint); // Challenge info here
               const {
                    code
               } = await inquirer.prompt([
                    {
                         'type': 'input',
                         'name': 'code',
                         'message': 'Enter code'
                    }
               ]);

               log.status(await ig.challenge.sendSecurityCode(code));
               return;
          }
     }
}

This is the full "media" object, from console.log

{ media:
   { taken_at: 1572683343,
     pk: '2168147484715474414',
     id: '2168147484715474414_23111643426',
     device_timestamp: 1572683340731,
     media_type: 1,
     code: 'B4WzqZnH13u',
     client_cache_key: 'MjE2ODE0NzQ4NDcxNTQ3NDQxNA==.2',
     filter_type: 0,
     image_versions2: { candidates: [Array] },
     original_width: 1080,
     original_height: 1080,
     user:
      { pk: 23111643426,
        username: 'howmanytreesleft',
        full_name: '🌲',
        is_private: false,
        profile_pic_url:
         'https://instagram.fkul10-1.fna.fbcdn.net/vp/ec28ef5be568762fcc47bb52b886cdd4/5E440E73/t51.2885-19/s150x150/73495498_1441744725977136_4969521068369772544_n.jpg?_nc_ht=instagram.fkul10-1.fna.fbcdn.net',
        profile_pic_id: '2164536498678832025_23111643426',
        has_anonymous_profile_picture: false,
        can_boost_post: false,
        can_see_organic_insights: false,
        show_insights_terms: false,
        reel_auto_archive: 'unset',
        is_unpublished: false,
        allowed_commenter_type: 'any' },
     can_viewer_reshare: true,
     caption_is_edited: false,
     comment_likes_enabled: false,
     comment_threading_enabled: false,
     has_more_comments: false,
     max_num_visible_preview_comments: 2,
     preview_comments: [],
     can_view_more_preview_comments: false,
     comment_count: 0,
     photo_of_you: false,
     caption: null,
     fb_user_tags: { in: [] },
     can_viewer_save: true,
     organic_tracking_token:
      'eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjYyZGQ5MGEzNzg1ZTRiNjVhY2ZjNjJmYTU0NzRlMWJiMjE2ODE0NzQ4NDcxNTQ3NDQxNCIsInNlcnZlcl90b2tlbiI6IjE1NzI2ODMzNDQxOTV8MjE2ODE0NzQ4NDcxNTQ3NDQxNHwyMzExMTY0MzQyNnw0YTg4ZmEzY2YxNzk1YjRhNjlmNzcyNDFlMGMyOGYwZTRjZDc1Mzg3YzNlMjhlZWU3MWI1M2NhZmY5OTNiMDExIn0sInNpZ25hdHVyZSI6IiJ9' },
  upload_id: '1572683340731',
  status: 'ok' }

Thanks in advance for any help!

Nerixyz commented 5 years ago

Unfortunately this isn't an issue with the library itself, more with instagram. You can search for "regular" users experiencing a similar problem. Some say it's because there are too many hashtags or malformed ones. This could also happen if you're somehow flagged. I had a similar problem a while ago I've since added two things:

blaxbla123 commented 5 years ago

@Nerixyz Hmm... facinating. Thanks for the lead! Didn't think that something so seemingly broken could be so intentional at the same time. I did some googling and found out instagram was picky about links in bios. Mine was to "teamtrees.org", which was apparently malicious according to the instagram overlords. Removed it and captions started appearing.