Fetching shared profiles dms #1197
Geraltcoder
started this conversation in
General
Replies: 3 comments 2 replies
-
Read this https://adw0rd.github.io/instagrapi/usage-guide/direct.html and show your code example in which you are unable to get profiles |
Beta Was this translation helpful? Give feedback.
2 replies
-
these are three codes which I'm trying to use 1)from instagrapi import Client
from instagrapi.exceptions import ChallengeRequired
from datetime import datetime
# Initialize the client
client = Client()
# Prompt for login credentials
username = input("Enter Instagram username: ")
password = input("Enter Instagram password: ")
try:
client.login(username, password)
except ChallengeRequired as e:
# Handle challenge required
challenge_url = e.challenge_url
challenge_code = input(f"Enter the code sent to {challenge_url}: ")
client.challenge_login(challenge_url, challenge_code)
# Open the direct thread with the specific user
# Get the direct message threads for the current user
threads = client.direct_threads()
# Find the thread with the specific user
for thread in threads:
# Check if the thread has the specific user as a participant
if any(participant.id == 'user conversation id' for participant in thread.participants):
# Get the direct messages in the thread
messages = client.direct_thread_by_id(thread.id).messages
# Iterate through the messages in the thread
for message in messages:
# Check if the message is from or to the specific user
if (message.sender_id == message send and 'username' in message.text) or \
(message.sender_id != 'messsage sender id and 'usernmae' not in message.text):
# Process the message as needed
print(message.text) ### 2) # Open the direct thread with the specific user
thread = client.direct_thread_by_participants([user_id])
# Iterate through the messages in the conversation
for message in thread.messages:
# Check if the message is from or to the specific user
if ('specific_username' in message.text and message.user_id == client.user_id) or \
('specific_username' not in message.text and message.user_id != client.user_id):
# Check if the message is a media share
if message.media_share:
# Get the message creation time
created_time = datetime.utcfromtimestamp(message.created_at)
# Check if the message creation time is within the time range
if start_date <= created_time <= end_date:
# Get the shared profile data
user_id = message.media_share.user.pk
username = message.media_share.user.username
# Print the shared profile data
print(f"{username} (ID: {user_id}) shared their profile") 3)from instagrapi import Client
from datetime import datetime
# Initialize the client
client = Client()
# Prompt for login credentials
username = input("Enter Instagram username: ")
password = input("Enter Instagram password: ")
client.login(username, password)
# Get the direct thread with the specific user
specific_username = input("Enter the username of the specific user: ")
thread = client.direct_thread(specific_username)
# Define the time range for message retrieval
start_date = datetime(year=2023, month=3, day=1)
end_date = datetime(year=2023, month=3, day=24)
# Iterate through the messages in the thread
for message in thread:
# Check if the message is from or to the specific user
if (specific_username in message.text and message.user_id == client.user_id) or \
(specific_username not in message.text and message.user_id != client.user_id):
# Check if the message is a media share
if message.media_share:
# Get the message creation time
created_time = datetime.utcfromtimestamp(message.created_at)
# Check if the message creation time is within the time range
if start_date <= created_time <= end_date:
# Get the shared profile data
user_id = message.media_share.user.pk
username = message.media_share.user.username
# Print the shared profile data
print(f"{username} (ID: {user_id}) shared their profile") |
Beta Was this translation helpful? Give feedback.
0 replies
-
And not in one of them you use dump/load settings, read the instagrapi documentation first |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I’m trying to fetch some shared profiles sent to a user in direct messages but I’m unable to find the correct method or the code, I’ve searched the whole direct methods but I can’t wrap my head around it. Can someone help me? I also unable to understand what is a thread?
Beta Was this translation helpful? Give feedback.
All reactions