instagrapi icon indicating copy to clipboard operation
instagrapi copied to clipboard

[BUG] DM doesn't seem to work

Open mycroftcanner opened this issue 1 year ago • 1 comments

import os
from instagrapi import Client
import logging

logger = logging.getLogger()

# Define the username or obtain it from an environment variable
USERNAME = os.getenv("IG_USERNAME")

# Initialize Instagram Client
cl = Client()

# Attempt to load session, otherwise use environment variables for login
if not cl.load_settings("session.json"):
    IG_USERNAME = os.getenv("IG_USERNAME", "default_username")
    IG_PASSWORD = os.getenv("IG_PASSWORD", "")
    if not IG_PASSWORD:
        logger.error("Instagram password not provided in environment variables")
        sys.exit(1)
    cl.login(IG_USERNAME, IG_PASSWORD) 
    cl.dump_settings("session.json")

# Get user ID from username
user_id = cl.user_id_from_username(USERNAME)
print(f"User ID for {USERNAME}: {user_id}")

# Assuming you've already logged in and set up the client as shown previously

# Get all threads from the inbox
threads = cl.direct_threads()

# Count the number of conversations
number_of_conversations = len(threads)

# Print out the count
print(f"Total number of conversations in the inbox: {number_of_conversations}")

Total number of conversations in the inbox: 0

Is direct messages still working?

mycroftcanner avatar Jan 15 '24 15:01 mycroftcanner

Possibly related to #1735

claell avatar Jan 19 '24 17:01 claell