我正在尝试制作可以将图像电报上传到 Instagram 的机器人

问题描述 投票:0回答:1

S C:\Users\hp\Desktop\telegram>  c:; cd 'c:\Users\hp\Desktop\telegram'; & 'C:\Program Files\Python312\python.exe' 'c:\Users\hp\.vscode\extensions\ms-python.python-2023.22.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '54413' '--' 'C:\Users\hp\Desktop\telegram\f.py'  2024-01-26 14:40:41,217 - INFO - Instabot version: 0.117.0 Started 2024-01-26 14:40:41,222 - INFO - Not yet logged in starting: PRE-LOGIN FLOW! 2024-01-26 14:40:48,775 - ERROR - Request returns 400 error! 2024-01-26 14:40:48,776 - INFO - Instagram's error message: The username you entered doesn't appear to belong to an account. Please check your username and try  again. 2024-01-26 14:40:48,777 - INFO - Error type: invalid_user 2024-01-26 14:40:48,778 - ERROR - Failed to login go to instagram and change your password 2024-01-26 14:40:48,778 - INFO - Username or password is incorrect. PS C:\Users\hp\Desktop\telegram> 

from telegram import Update
from telegram.ext import CommandHandler, CallbackContext, Application
from instabot import Bot
import asyncio



# Initialize Telegram bot
TELEGRAM_TOKEN = ""
bot = Bot()

# Initialize Instagram bot with App ID and App Secret
INSTAGRAM_APP_ID = ""
INSTAGRAM_APP_SECRET = ""
bot.login(username=INSTAGRAM_APP_ID, password=INSTAGRAM_APP_SECRET)

async def start(update: Update, context: CallbackContext) -> None:
    await update.message.reply_text('Welcome to the Instagram Image Uploader Bot! Please enter your Instagram username and password in the format: /login username password')

async def login(update: Update, context: CallbackContext) -> None:
    args = context.args
    if len(args) != 2:
        await update.message.reply_text('Please provide your Instagram username and password in the format: /login username password')
        return
    username = 'my_username '# i tried with @ and without @
    password = 'my_password'
    context.user_data['username'] = username
    context.user_data['password'] = password
    await update.message.reply_text(f'Thank you {username}! Now send me an image to upload to Instagram.')

async def handle_image(update: Update, context: CallbackContext) -> None:
    if 'username' not in context.user_data or 'password' not in context.user_data:
        await update.message.reply_text('Please login first using /login username password')
        return
    file_id = update.message.photo[-1].file_id
    file = context.bot.get_file(file_id)
    file.download('image.jpg')

    # Upload image to Instagram
    bot.upload_photo("image.jpg", caption="Uploaded from Telegram bot")

    # Send a message indicating successful upload
    await update.message.reply_text("Image uploaded to Instagram successfully!")

async def main():
    application = Application.builder().token(TELEGRAM_TOKEN).build()  # Using Application from telegram.ext

    start_handler = CommandHandler('start', start)
    login_handler = CommandHandler('login', login)  # Removed pass_args=True
   
    application.add_handler(start_handler)
    application.add_handler(login_handler)
    application.add_handler(MessageHandler(Filters.photo, handle_image))  # Handle image messages
   
    try:
        await application.run_polling()  # Using run_polling method of Application
    finally:
        await application.shutdown()
        await asyncio.gather(*asyncio.all_tasks())

if __name__ == '__main__':
    asyncio.run(main())

为什么我面临这个问题,请帮助我 这是终端中的错误 C:; cd 'c:\Users\hp\Desktop elegram'; & 'C:\Program Files\Python312\python.exe' 'c:\Users\hp.vscode xtensions\ms-python.python-2023.22.1\pythonFiles\lib\python\debugpy dapter/../. .\debugpy\launcher' '54413' '--' 'C:\Users\hp\Desktop elegram .py' 2024-01-26 14:40:41,217 - 信息 - Instabot 版本:0.117.0 已开始 2024-01-26 14:40:41,222 - 信息 - 尚未登录开始:预登录流程! 2024-01-26 14:40:48,775 - 错误 - 请求返回 400 错误! 2024-01-26 14:40:48,776 - 信息 - Instagram 的错误消息:您输入的用户名似乎不属于帐户。请检查您的用户名并尝试 再次。 2024-01-26 14:40:48,777 - 信息 - 错误类型:invalid_user 2024-01-26 14:40:48,778 - 错误 - 无法登录,请前往 Instagram 并更改密码 2024-01-26 14:40:48,778 - 信息 - 用户名或密码不正确。 PS C:\Users\hp\Desktop elegram>

python file-upload instagram telegram-bot instagram-api
1个回答
0
投票

您似乎在此处向 insbot.login 方法传递了错误的 Instagram ID 和密码

# Initialize Instagram bot with App ID and App Secret INSTAGRAM_APP_ID = "" #Should pass a valid username INSTAGRAM_APP_SECRET = "" #Should pass a valid Secret key bot.login(username=INSTAGRAM_APP_ID, password=INSTAGRAM_APP_SECRET)

© www.soinside.com 2019 - 2024. All rights reserved.