subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.37k stars 684 forks source link

[BUG] DM doesn't seem to work #1748

Open mycroftcanner opened 10 months ago

mycroftcanner commented 10 months ago
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?

claell commented 9 months ago

Possibly related to #1735