简体   繁体   English

如何通过 python 请求创建 Instagram 帐户

[英]How to make a instagram account via python requests

Im working on a larger project that will use this feature of making a Instagram account.我正在做一个更大的项目,该项目将使用创建 Instagram 帐户的这一功能。 So far i get the server to understand my reqeust though it wont make a account.到目前为止,我让服务器了解我的请求,尽管它不会创建帐户。 I assume im missing some info in the request but im not sure.我假设我在请求中遗漏了一些信息,但我不确定。

def main():
    username = ""
    password = ""
    email_to_use = ""
    first_name = ""

    time = str(int(datetime.datetime.now().timestamp()))
    enc_password = f"#PWD_INSTAGRAM_BROWSER:0:{time}:{password}"
    session = requests.Session()
    # set a cookie that signals Instagram the "Accept cookie" banner was closed
    session.cookies.set("ig_cb", "2")
    session.headers.update({'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36'})
    session.headers.update({'Referer': 'https://www.instagram.com'})
    res = session.get('https://www.instagram.com')

    csrftoken = None
    for key in res.cookies.keys():
        if key == 'csrftoken':
            csrftoken = session.cookies['csrftoken']
    session.headers.update({'X-CSRFToken': csrftoken})

    login_data = {'username': username, 'enc_password': enc_password, 'email': email_to_use, 'first_name': first_name,}


    login = session.post('https://www.instagram.com/accounts/web_create_ajax/attempt/', data=login_data, allow_redirects=True)
    session.headers.update({'X-CSRFToken': login.cookies['csrftoken']})

    cookies = login.cookies
    print(login.text)


that code returns该代码返回

{"account_created":false,"dryrun_passed":true,"username_suggestions":["jsonhews","floristry_zrpc","jsonhews2","jsonhews43","jsonhews524","jsonhews3154","jsonhews7","jsonhews64","jsonhews356","jsonhews2146","jsonhews3"],"status":"ok"}

Not sure what i could do so if you have any ideas id love to hear.如果你有任何我喜欢听的想法,我不确定我能做什么。 Thanks.谢谢。

Based on the JSON response, it looks like maybe you're trying to send a username that's already taken.根据 JSON 响应,您可能正在尝试发送已被占用的用户名。 Try using one that you're certain is unique and see if the problem still occurs.尝试使用您确定是独一无二的,看看问题是否仍然存在。

This happened to me too.这也发生在我身上。 I am also writing a bot to create an Instagram account with Selenium, and when the bot enters the code sent to the email and clicks the next button, it returns the same values, and I checked and found that these accounts have been created.我还在编写一个机器人来创建一个带有 Selenium 的 Instagram 帐户,当机器人输入发送到 email 的代码并单击下一步按钮时,它返回相同的值,我检查并发现这些帐户已经创建。 But once I logged in with the same username and password, I found that these accounts were detected as bots and suspended.但是一旦我使用相同的用户名和密码登录,我发现这些帐户被检测为机器人并被暂停。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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