import requests

import json

# Konfigurasi

access_token = "IGAAbDRJqoXZAJBZAE9nSHJVZAWlZAVEpaQkdUb1hYc0pQbEp1SDUwT1dFZAVlBeHBmZAkVYbjBJRExoa3pPN3NyUkhraDdBVGs0WDlGV0EzRHVQZAlF3dVVHWVBvblEzeUY2QWRMMkZAhM2ZA4eTQxQ0E1S1ZAVNERwb1lYYXc1S0puZAERtQm5mSGJUVFMyN2ZA3"

instagram_account_id = "9654344654586349"

# Fungsi untuk mendapatkan daftar postingan (media) terbaru Anda

def get_instagram_posts():

    url = f"https://graph.instagram.com/v18.0/{instagram_account_id}/media"

    params = {

        "access_token": access_token,

        "fields": "id,caption,media_type,permalink,timestamp"

    }

    response = requests.get(url, params=params)

    

    if response.status_code == 200:

        return response.json().get("data", [])

    else:

        print(f"Error mendapatkan post: {response.text}")

        return []

# Jalankan fungsi untuk mendapatkan daftar post

posts = get_instagram_posts()

# Tampilkan ID dan informasi dasar tentang setiap post

for post in posts:

    post_id = post["id"]

    caption = post.get("caption", "No caption")

    timestamp = post.get("timestamp")

    

    # Cetak informasi post

    print(f"Post ID: {post_id}")

    print(f"Caption: {caption[:50]}..." if len(caption) > 50 else f"Caption: {caption}")

    print(f"Posted at: {timestamp}")

    print("-" * 30)
