【问题标题】:Can I automatically upload pictures to Instagram?我可以自动将图片上传到 Instagram 吗?
【发布时间】:2020-05-08 18:43:12
【问题描述】:

我知道之前有人问过这个问题,但既然已经问了这么久,我会再问一次,我可以通过 InstagramAPI 自动将图片上传到 Instagram,如果没有,还有其他安全的方法吗? (最好使用python),我的日程很忙,没有足够的时间发布图片,所以我想自动化这个过程。 这是我尝试使用 instapy-cli 的方法

from instapy_cli import client

username = 'my_username'

password = 'my_password'

image = 'image.jpg'

text = 'test caption'

with client(username, password) as cli:
    cli.upload(image, text)

这是错误

[IG] not found cookie/cookie_file >> login as default
Error is >>
Error parsing error response: Expecting value: line 1 column 1 (char 0)
    Bad Request

Something went bad.
Please retry or send an issue on https://github.com/b3nab/instapy-cli

Traceback (most recent call last):
  File "C:/Users/firmi/.PyCharmCE2018.1/config/scratches/Projects/test.py", line 12, in <module>
    cli.upload(image, text)
  File "C:\Users\firmi\PycharmProjects\MyProjects\venv\lib\site-packages\instapy_cli\cli.py", line 153, in upload
    raise IOError("Unable to upload.")
OSError: Unable to upload.

我尝试过使用“instabot”、“InstagramAPI”、“instagram-private-api”等

【问题讨论】:

  • 尝试时会发生什么?
  • 你到底是什么意思?我尝试了一些声称具有上传照片功能的库,但它们都只是返回错误。
  • 您好,向我们展示您的尝试。提供一些代码来帮助我们分析你哪里做错了。

标签: python python-3.x instagram instagram-api


【解决方案1】:

绝对可以,

pip install instapy-cli

#Code
from instapy_cli import client

username = 'username' #your username
password = '**********' #your password 
image = 'Hi_instagram.png' #here you can put the image directory
text = 'Here you can put your caption for the post'

with client(username, password) as cli:
   cli.upload(image, text)

更多详情请阅读以下帖子。

https://medium.com/@selfengineeredd/how-to-post-on-instagram-using-python-fd8b08050a85

使用的包 - https://pypi.org/project/instapy-cli/

【讨论】:

  • 我做了同样的事情,但它给了我一个错误 "IOError("Unable to upload.")"
  • 能否请您添加错误日志,IOError表示可能无法找到图片位置,
  • 我在帖子中添加了它们
  • 不起作用,出现一堆错误:[IG] 未找到 cookie/cookie_file >> 默认登录 找不到记录器“instagram_private_api.errors”的处理程序错误是 >> 未找到出事了。请重试或在github.com/b3nab/instapy-cli Traceback 上发送问题(最近一次通话最后一次):文件“upload_to_instagram.py”,第 9 行,在 cli.upload(image, text) 文件“/home/paul/.local/ lib/python2.7/site-packages/instapy_cli/cli.py",第 153 行,在上传中引发 IOError("Unable to upload.") IOError: Unable to upload.
  • 在我发布答案时,它就像一个魅力,如果它现在不起作用,对不起。 :(
【解决方案2】:

安装instabot:

pip install instabot

然后新建一个python脚本:

vim upload_to_instagram.py

把这个放到脚本里:

from instabot import Bot 
bot = Bot() 
bot.login(username = "user_name",  
          password = "user_password") 
bot.upload_photo("Technical-Scripter-2019.jpg", 
                 caption ="Technical Scripter Event 2019") 

保存脚本并关闭它,然后运行它:

python upload_to_instagram.py

【讨论】:

  • 感谢您的回答!但是每次我运行代码时都会创建一个配置文件,我需要在每次运行之前删除它才能使其工作,但我有一个每小时运行一次代码的时间表。问题是在代码运行时正在写入配置文件,所以我无法删除它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多