인터넷 마케팅을 하거나 브랜드 이미지를 알릴 때 인스타그램은 필수적인 플랫폼입니다. 하지만 포스트를 자주 올리는 마케터나 인플루언서에게는 반복적인 업로드 과정이 번거로울 수 있습니다. 이를 자동화하여 효율적으로 관리하는 방법을 소개합니다.

이 글에서는 다음 과정을 다룹니다:

  • 쉘 스크립트를 이용해 인스타그램 포스트 자동 업로드
  • AWS S3를 사용해 이미지 업로드
  • AI 이미지 생성 API를 활용해 자동으로 콘텐츠 제작
  • 인스타그램 API에서 토큰을 얻는 방법
  • 페이스북 개발자 계정을 이용해 인스타그램 API 설정

1️⃣ 쉘 스크립트로 인스타그램 포스트 자동 업로드

쉘 스크립트를 사용하면 이미지 URL과 캡션을 포함해 인스타그램 포스트를 자동으로 게시할 수 있습니다.
다음 코드를 활용하면 간단한 API 호출로 포스트를 업로드할 수 있습니다.

#!/bin/bash

# 변수 설정
USER_ID="1111111111111111111"
IMAGE_URL="https://bucket.s3.us-east-2.amazonaws.com/icon.png"
CAPTION="Cursor Tail #chrome #extension #chrome-extension"
ACCESS_TOKEN="YourToken"

# API URL 설정
API_URL="https://graph.instagram.com/v22.0/$USER_ID/media"

# JSON 데이터 생성
JSON_PAYLOAD=$(cat <<EOF
{
    "caption": "$CAPTION",
    "image_url": "$IMAGE_URL"
}
EOF
)

# API 호출
curl -X POST "$API_URL" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer $ACCESS_TOKEN" \
     -d "$JSON_PAYLOAD"

이제 쉘 스크립트를 실행하면 자동으로 포스트가 업로드됩니다.


2️⃣ AWS S3를 이용해 이미지 업로드

인스타그램 포스트에서 사용할 이미지를 저장하기 위해 AWS S3를 활용할 수 있습니다.
S3 버킷을 생성한 후 이미지를 업로드하면 공개 URL을 얻을 수 있습니다.

이미지 업로드 코드

aws s3 cp my-image.png s3://my-bucket/my-image.png --acl public-read

업로드된 이미지 URL 확인

https://my-bucket.s3.amazonaws.com/my-image.png

3️⃣ AI 이미지 생성 API 활용

AI 이미지 생성 API를 이용하면 자동으로 디자인된 이미지를 생성할 수 있습니다.
이를 활용하면 포스트 콘텐츠를 빠르게 제작할 수 있습니다.

DALL·E API를 이용한 이미지 생성 예제

curl -X POST "https://api.openai.com/v1/images/generations" \
    -H "Authorization: Bearer YOUR_OPENAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "A futuristic abstract pattern",
      "n": 1,
      "size": "1024x1024"
    }'

4️⃣ 인스타그램 API 토큰 얻는 방법

인스타그램 API를 활용하려면 엑세스 토큰을 발급받아야 합니다.

토큰 발급 API 요청

curl -X GET "https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&access_token=YOUR_SHORT_LIVED_TOKEN"

5️⃣ 페이스북 개발자 계정을 이용한 설정

인스타그램 API를 사용하려면 페이스북 개발자 계정을 등록해야 합니다.


결론

AI 이미지 생성 API를 이용해 키워드로 이미지를 만들고, 이를 아마존 S3에 업로드한 다음, 인스타그램 API를 이용해 자동으로 포스트를 올리는 방법을 소개했습니다.

How to Automate Instagram Posting

When marketing online or building brand awareness, Instagram is an essential platform. However, marketers and influencers who frequently post may find the process time-consuming. To simplify this, let's explore how to automate Instagram posts for efficiency.

This guide covers:

  • Using a shell script to automate Instagram posts
  • Uploading images to AWS S3 for hosting
  • Generating images with AI image generation APIs
  • Obtaining an Instagram API token
  • Setting up Instagram API with a Facebook Developer Account

1️⃣ Automating Instagram Posts Using a Shell Script

A shell script allows you to automate posting images and captions to Instagram.
Use this script to send an API request for uploading a post.

#!/bin/bash

# Variables
USER_ID="1111111111111111111"
IMAGE_URL="https://bucket.s3.us-east-2.amazonaws.com/icon.png"
CAPTION="Cursor Tail #chrome #extension #chrome-extension"
ACCESS_TOKEN="YourToken"

# API URL
API_URL="https://graph.instagram.com/v22.0/$USER_ID/media"

# JSON Payload
JSON_PAYLOAD=$(cat <<EOF
{
    "caption": "$CAPTION",
    "image_url": "$IMAGE_URL"
}
EOF
)

# API Call
curl -X POST "$API_URL" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer $ACCESS_TOKEN" \
     -d "$JSON_PAYLOAD"

After running this script, your Instagram post will be automatically uploaded.


2️⃣ Uploading Images to AWS S3

To host images for Instagram posts, AWS S3 can be used to store and serve files via public URLs.

Uploading an Image to S3

aws s3 cp my-image.png s3://my-bucket/my-image.png --acl public-read

Retrieving the Image URL

https://my-bucket.s3.amazonaws.com/my-image.png

Once uploaded, this URL can be used to attach images to Instagram posts.


3️⃣ Generating AI-Generated Images Using an API

AI image generation APIs allow you to automatically create images based on keywords.

Using DALL·E API to Generate an Image

curl -X POST "https://api.openai.com/v1/images/generations" \
    -H "Authorization: Bearer YOUR_OPENAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "A futuristic abstract pattern",
      "n": 1,
      "size": "1024x1024"
    }'

The API returns a generated image, which can then be uploaded to AWS S3.


4️⃣ Obtaining an Instagram API Token

To use the Instagram API, an access token is required. The token allows secure interaction with Instagram’s API.

Requesting an Access Token

curl -X GET "https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&access_token=YOUR_SHORT_LIVED_TOKEN"

5️⃣ Setting Up Instagram API with Facebook Developer Account

To access the Instagram API, a Facebook Developer Account is needed:

  • Go to Meta for Developers
  • Register a developer account and create an Instagram App
  • Enable Instagram Graph API

Conclusion

This guide introduced a method for automating Instagram posts by:
Generating images using an AI API
Uploading images to AWS S3
Using the Instagram API to schedule posts automatically

0개의 댓글