简体   繁体   中英

send direct message using instagrapi

I'm tryin to send DM's with instagrapi, I've followed the docs up to a point and currently this is my code

from instagrapi import Client

cl = Client()
cl.login(USERNAME, PASSWORD)

cl.direct_send("This is a message", ['53979279619', '54365742245', '51215837511', '53058609422', '54547827808'])

However when I run the code I get this error

requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: 

https://i.instagram.com/api/v1/direct_v2/threads/broadcast/text/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bot.py", line 67, in <module>
    main(file_name)
  File "bot.py", line 42, in main
    cl.direct_send(f"{message}", followers_id)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\instagrapi\mixins\direct.py", line 254, in direct_send
    result = self.private_request(
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\instagrapi\mixins\private.py", line 447, in private_request
    raise e
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\instagrapi\mixins\private.py", line 434, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "C:\Users\HP\AppData\Local\Programs\Python\Python38-32\lib\site-packages\instagrapi\mixins\private.py", line 326, in _send_private_request
    raise ClientForbiddenError(e, response=e.response, **last_json)
instagrapi.exceptions.ClientForbiddenError: {"action":"item_ack","status_code":"403","payload":{"client_context":"6800073986551502662","message":"This may be due to their app version or other settings."},"status":"fail"}

I'm 100% sure my account isn't banned and still active, no matter the account I use it still gives me the same error. Any help fixing this would be really appreciated

I'm not really sure what the error is, but here is a basic way to send direct messages

from instagrapi import Client

cl = Client()
cl.login(USERNAME, PASSWORD)
send_to = cl.user_id_from_username(username="instagram name")

cl.direct_send(text="Message", user_ids=[send_to])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM