简体   繁体   English

使用 Python 将图像上传到 Instagram

[英]Upload images to instagram using Python

I'm trying to do a simple Instagram python bot in order to upload images in my Instagram profile.我正在尝试做一个简单的 Instagram python 机器人,以便在我的 Instagram 个人资料中上传图片。 I've already tried the most common libraries (InstagramAPI, instapy, insta-cly).我已经尝试过最常用的库(InstagramAPI、instapy、insta-cly)。 While I was searching I found out that Instagram has changed something making those libraries useless.在我搜索时,我发现 Instagram 改变了一些东西,使这些库变得毫无用处。

Is there any library I can use?有没有我可以使用的图书馆? I know thatI can use Selenium in order to make it go but I'm wondering if there is any shortcut.我知道我可以使用 Selenium 来使其成为 go 但我想知道是否有任何捷径。

Trank you!夸你!

try this library: instabot https://pypi.org/project/instabot/试试这个库:instabot https://pypi.org/project/instabot/

example of code for uploading an image:上传图片的代码示例:

from instabot import Bot

bot = Bot()
bot.login(username="instagram_username", password="your_password")

file = open('path_to_your_image', 'r')
bot.upload_photo(file, caption="your post caption")

Instabot python library allows you to upload images, stories, videos, make comments and much much more, but there are problems that are not resolved in other answers, so I wrote this code that takes care about all of that for you. Instabot python 库允许您上传图像、故事、视频、发表评论等等,但有些问题在其他答案中没有解决,所以我编写了这段代码来为您处理所有这些问题。

from instabot import Bot
import os
import shutil


def clean_up():
    dir = "config"
    remove_me = "imgs\img.jpg.REMOVE_ME"
    # checking whether config folder exists or not
    if os.path.exists(dir):
        try:
            # removing it because in 2021 it makes problems with new uploads
            shutil.rmtree(dir)
        except OSError as e:
            print("Error: %s - %s." % (e.filename, e.strerror))
    if os.path.exists(remove_me):
        src = os.path.realpath("imgs\img.jpg")
        os.rename(remove_me, src)


def upload_post():
    bot = Bot()

    bot.login(username="your_username", password="your_password")
    bot.upload_photo("imgs/img.jpg", caption="Caption for the post")


if __name__ == '__main__':
    clean_up()
    upload_post()

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

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