-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Direct Message (dm) #1890
Comments
Alternative DM with Instagrapi from instagrapi import Client log in to your Instagram accountapi = Client() search for the receiver's user by usernameuser = api.search_users(receiver_username) from datetime import datetime if user: # if receiver's user is found log out of your Instagram accountapi.logout() |
from instagrapi import Client
--- Initialize Instagrapi client
client = Client()
--- Login to your Instagram account
username =
password =
client.login(username, password)
thread = client.direct_threads(2)[0]
--- Target user's username
target_username =
--- Get the user ID of the target user
user_info_dict = client.user_info_by_username_v1(username).dict()
target_user_id = user_info_dict['pk']
--- Your message
message = "Hello"
--- Send a direct message
try:
client.direct_send(message, target_user_id)
print("Direct message sent successfully!")
except Exception as e:
print(f"Error sending direct message: {e}")
Returns
Error sending direct message: {"action":"item_ack","status_code":"403","message":"We're sorry, but something went wrong. Please try again.","payload":{"client_context":"6800090932895711343","message":"We're sorry, but something went wrong. Please try again."},"status":"fail"}
Please assist
The text was updated successfully, but these errors were encountered: