我正在寻找一个工具,可以让我张贴到Instagram从python

2024-06-06 12:25:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找一个工具,允许我张贴到Instagram从python

我想使用Heroku或GCP cloud scheduler之类的调度器来自动化这个过程,因此我们认为使用GUI的selenium之类的东西并不真正合适。 (不过,也可以使用selenium来运行它。)

我已经尝试过instapy cli和instabot,但它们现在似乎不可用

https://github.com/b3nab/instapy-cli

https://instagrambot.github.io/


Tags: 工具httpsgithubcloudherokucli过程selenium
2条回答

您可以从Automating Instagram Posts with Python and Instagram Graph API尝试此代码

import requests
import config
import json
def postInstagramQuote():
#Post the Image
    image_location_1 = 'http:path-to-your-image.com/img/image-name.jpg'
    post_url = 'https://graph.facebook.com/v10.0/{}/media'.format(config.ig_user_id)
payload = {
    'image_url': image_location_1,
    'caption': 'Get jobs online on https://careers-portal.co.za #career #hiring #jobs #job #jobssouthafrica #hiringnow,
    'access_token': config.user_access_token
    }
    r = requests.post(post_url, data=payload)
    print(r.text)
result = json.loads(r.text)
    if 'id' in result:
        creation_id = result['id']
second_url = 'https://graph.facebook.com/v10.0/{}/media_publish'.format(config.ig_user_id)
        second_payload = {
        'creation_id': creation_id,
        'access_token': config.user_access_token
        }
        r = requests.post(second_url, data=second_payload)
        print('    Just posted to instagram    ')
        print(r.text)
    else:
        print('HOUSTON we have a problem')
postInstagramQuote()

提醒:您只能从Instagram商业账户发帖,不能向您的个人Instagram账户发帖

您可以尝试the official Instagram API,您必须为其设置一个business account

相关问题 更多 >