[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M76T82ZQ2G8XBX4CP6F2CG43":3,"skill-same:01M76T82ZQ2G8XBX4CP6F2CG43":69},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":37,"commitSha":38,"skillDirectory":39,"forksCount":14,"repositoryHtmlUrl":40,"repositoryHomepageUrl":6,"ownerHtmlUrl":41,"ownerBlogUrl":42,"ownerDescription":43,"updatedAt":44,"install":45,"resources":58},"01M76T82ZQ2G8XBX4CP6F2CG43","facebook-automation-suite",null,"คู่มือและการสร้างสคริปต์สำหรับจัดการ Facebook Fanpage (โพสต์ออโต้, ดูดข้อมูล, ดึงคอมเมนต์) ผ่าน Python","SatangThevalue\u002Fai-skills","SatangThevalue","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F17944930?v=4","01M756VHQQ58XSM5PDS03W79VY","Sa-Tang","01M756VHRNYXRY7HM230S4YHVV",0,"MIT","https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fmarketing\u002Ffacebook-automation-suite\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: facebook-automation-suite\ndescription: \"คู่มือและการสร้างสคริปต์สำหรับจัดการ Facebook Fanpage (โพสต์ออโต้, ดูดข้อมูล, ดึงคอมเมนต์) ผ่าน Python\"\nversion: 1.0.0\nauthor: Tonthong\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [facebook, automation, api, scraping, social-media]\n    related_skills: [content-marketing-2026-2027, ai-fluency-framework]\n---\n\n# Facebook Fanpage Automation Suite\n\nสกิลนี้รวบรวมเทคนิคและการใช้งานไลบรารี Python ยอดนิยม 2 ตัวในการจัดการ Facebook Fanpage สำหรับโปรเจคหาเงินอัตโนมัติ (Zero-Touch) โดยแบ่งออกเป็น \"สายขาว\" (ใช้ Official API) และ \"สายเทา\" (ใช้ Web Scraper)\n\n## 1. ไลบรารีที่เลือกใช้\n\n| เป้าหมาย | ชื่อไลบรารี | คำอธิบาย |\n| :--- | :--- | :--- |\n| **สายโพสต์ \u002F แอดมิน (สายขาว)** | `facebook-python-business-sdk` (Official) | เครื่องมือทางการจาก Facebook (Meta) อัปเดตล่าสุด ใช้ยิงโฆษณา, ดึงคอมเมนต์, โพสต์คอนเทนต์ลงเพจตัวเอง |\n| **สายดูดข้อมูล (สายเทา\u002Fวิจัย)** | `facebook-scraper` | เครื่องมือดึงข้อมูล (โพสต์, รูป, คอมเมนต์) จาก \"เพจคู่แข่ง\" หรือกลุ่มสาธารณะ โดยไม่ต้องขอ API Key |\n\n---\n\n## 2. วิธีการติดตั้ง\n\n```bash\n# ติดตั้งผ่าน uv ภายใน Virtual Environment ของเรา\nuv pip install facebook-business facebook-scraper\n```\n\n---\n\n## 3. รูปแบบการใช้งาน (Recipes)\n\n### Recipe 3.1: โพสต์คอนเทนต์\u002Fรูปภาพลงเพจตัวเอง (สายขาว)\n*ใช้ `facebook-python-business-sdk` เพื่อให้ AI สามารถนำคอนเทนต์ที่สร้างเสร็จแล้วไปโพสต์ลงเพจได้เองทุกวัน*\n\n**ข้อกำหนด:** ต้องมี `PAGE_ACCESS_TOKEN` และ `PAGE_ID` (ได้จากการสร้าง App ใน Facebook Developers)\n\n```python\nimport os\nfrom facebook_business.api import FacebookAdsApi\nfrom facebook_business.adobjects.page import Page\n\ndef auto_post_to_page(message: str, image_url: str = None):\n    # กำหนดค่าตัวแปร\n    access_token = os.getenv('FB_PAGE_ACCESS_TOKEN')\n    page_id = os.getenv('FB_PAGE_ID')\n    \n    # ยืนยันตัวตน\n    FacebookAdsApi.init(access_token=access_token)\n    page = Page(page_id)\n    \n    try:\n        if image_url:\n            # โพสต์พร้อมรูปภาพ\n            page.create_photo(params={\n                'url': image_url,\n                'caption': message\n            })\n        else:\n            # โพสต์ข้อความล้วน\n            page.create_feed(params={\n                'message': message\n            })\n        print(\"✅ Posted successfully to Facebook Page!\")\n    except Exception as e:\n        print(f\"❌ Failed to post: {e}\")\n```\n### Recipe 3.1.2: การจัดการโพสต์ คอมเมนต์ และวิดีโอ (Graph API เชิงลึก)\n*สามารถนำไปประยุกต์ใช้ในการแก้ไขโพสต์, ตอบกลับคอมเมนต์ (Auto-reply), หรือโพสต์ Video Reels ได้*\n\n```python\nfrom facebook_business.adobjects.pagepost import PagePost\nfrom facebook_business.adobjects.comment import Comment\n\n# 1. แก้ไขโพสต์เดิม (Update Post)\ndef update_page_post(post_id: str, new_message: str):\n    post = PagePost(post_id)\n    try:\n        post.api_update(params={'message': new_message})\n        print(f\"✅ Post {post_id} updated!\")\n    except Exception as e:\n        print(f\"❌ Update failed: {e}\")\n\n# 2. ตอบกลับคอมเมนต์อัตโนมัติ (Reply to Comment)\ndef reply_to_comment(comment_id: str, reply_message: str):\n    comment = Comment(comment_id)\n    try:\n        # NOTE: การตอบคอมเมนต์ใช้ฟังก์ชันสร้างคอมเมนต์ซ้อนเข้าไป\n        comment.create_comment(params={'message': reply_message})\n        print(f\"✅ Replied to comment {comment_id}!\")\n    except Exception as e:\n        print(f\"❌ Reply failed: {e}\")\n\n# 3. โพสต์วิดีโอ (Reels \u002F Video)\ndef auto_post_video(page_id: str, video_filepath: str, description: str):\n    page = Page(page_id)\n    try:\n        video = page.create_video(params={\n            'description': description,\n            'published': 'true'\n        }, files={\n            'source': video_filepath\n        })\n        print(f\"✅ Video posted successfully! ID: {video.get('id')}\")\n        return video.get('id')\n    except Exception as e:\n        print(f\"❌ Video upload failed: {e}\")\n        return None\n\n### Recipe 3.1.3: Auto-Pin Comment สำหรับ Reels & Affiliate Link\n*Facebook Reels ในไทยไม่มีปุ่มตะกร้าเหมือน TikTok กลยุทธ์หลักในการทำ Affiliate และขายของคือ \"ยิงคอมเมนต์แรกอัตโนมัติแล้วสั่งปักหมุด (Pin Comment)\" ทันทีที่วิดีโอโพสต์สำเร็จ*\n\n```python\nimport requests\n\ndef post_and_pin_first_comment(page_access_token: str, post_id: str, comment_text: str):\n    \"\"\"\n    สร้างคอมเมนต์แรกใต้โพสต์\u002FReel แล้วสั่งปักหมุด (Pinned Comment)\n    \"\"\"\n    url = f\"https:\u002F\u002Fgraph.facebook.com\u002Fv19.0\u002F{post_id}\u002Fcomments\"\n    params = {\n        \"access_token\": page_access_token,\n        \"message\": comment_text\n    }\n    resp = requests.post(url, data=params).json()\n    comment_id = resp.get(\"id\")\n    if not comment_id:\n        print(f\"❌ Create comment failed: {resp}\")\n        return False\n\n    # สั่งปักหมุดคอมเมนต์ผ่าน Graph API\n    pin_url = f\"https:\u002F\u002Fgraph.facebook.com\u002Fv19.0\u002F{post_id}\"\n    pin_params = {\n        \"access_token\": page_access_token,\n        \"pinned_comment_id\": comment_id\n    }\n    pin_resp = requests.post(pin_url, data=pin_params).json()\n    if pin_resp.get(\"success\"):\n        print(f\"✅ Comment {comment_id} pinned successfully!\")\n        return True\n    else:\n        print(f\"⚠️ Pinning note: {pin_resp}\")\n        return True\n```\n```\n\n### Recipe 3.2: สแครปข้อมูลและคอมเมนต์จากเพจอื่น (สายดูดข้อมูล)\n*ใช้ `facebook-scraper` เหมาะกับการเอาไปส่องคู่แข่งว่าเขาขายของดีไหม ลูกค้าคอมเมนต์ว่าอะไร แล้วเอา Data นั้นมาให้ AI แต่งสคริปต์วิดีโอของเรา*\n\n**ข้อจำกัด:** Facebook ปรับโครงสร้างเว็บดักบ่อย สคริปต์นี้อาจจะติด Limit (ควรหน่วงเวลา และสลับ IP หากดึงเยอะ)\n\n```python\nfrom facebook_scraper import get_posts\nimport time\n\ndef scrape_competitor_page(page_name: str, pages_limit: int = 1):\n    print(f\"⏳ เริ่มดึงข้อมูลจากเพจ {page_name}...\")\n    results = []\n    \n    # วนลูปดึงโพสต์จากเพจ (แนะนำให้ตั้งหน่วงเวลา เพื่อไม่ให้โดนบล็อก)\n    for post in get_posts(page_name, pages=pages_limit, options={\"comments\": True}):\n        data = {\n            \"post_id\": post['post_id'],\n            \"text\": post['text'],\n            \"time\": post['time'].strftime('%Y-%m-%d %H:%M:%S') if post['time'] else None,\n            \"likes\": post['likes'],\n            \"comments_count\": post['comments'],\n            \"shares\": post['shares'],\n            \"top_comments\": []\n        }\n        \n        # เก็บข้อมูลคอมเมนต์ (เพื่อเอามาหา Pain point ลูกค้า)\n        if 'comments_full' in post:\n            for comment in post['comments_full'][:5]:  # เอาแค่ 5 คอมเมนต์เด่น\n                data['top_comments'].append(comment['comment_text'])\n                \n        results.append(data)\n        time.sleep(2) # หน่วงเวลาสำคัญมาก\n        \n    print(f\"✅ ดึงมาได้ {len(results)} โพสต์\")\n    return results\n```\n\n---\n\n## 4. แผนประยุกต์ใช้เพื่อ \"หาเงิน\"\nคุณสตางค์สามารถนำ 2 ไลบรารีนี้มาผูกกันใน Prefect Pipeline ได้เลย:\n1. **[Data Extraction]:** ใช้ `facebook-scraper` วิ่งไปดูดโพสต์สินค้าขายดีของเพจร้านดัง หรือเพจคู่แข่ง (ดูว่าลูกค้าคอมเมนต์ด่า หรือชมเรื่องอะไร)\n2. **[AI Ideation]:** นำข้อความที่ดึงมา (เช่น ลูกค้าด่าว่าสายชาร์จพังง่าย) ไปบอก LLM (CLIProxyAPI) ให้เขียนสคริปต์วิดีโอของเรา โดยเน้น Hook เรื่อง \"สายชาร์จถึกทน\"\n3. **[Auto-Publish]:** เมื่อ AI ทำคลิปและ Caption พร้อม HashTag เสร็จ ก็ใช้ `facebook-python-business-sdk` (Official) สั่งโพสต์คลิปนั้นลงเพจ Facebook \u002F Reels ของเราเองอัตโนมัติ\n4. **[Auto-Pin & Multi-Page Flipping]:** ปั้นชุดเพจ 10-15 เพจกระจาย 4 Niche (จิตวิทยา, พัฒนาตัวเอง, คำคม, การเงิน) โดยยิงคลิปสั้น 15-20 วินาที พร้อม Auto-Pin คอมเมนต์ดึงคนไป Affiliate หรือสะสมผู้ติดตาม 5,000-10,000 คนเพื่อขายต่อ (Flipping) ดูรายละเอียดแผนธุรกิจและเมทริกซ์ความเสี่ยงใน `references\u002Fpage-flipping-and-anti-ban.md`\n\n## 5. การวิเคราะห์ข้อมูลเพจด้วย requests + BeautifulSoup (ทางเลือกสำหรับเพจสาธารณะ)\nในกรณีที่ `facebook-scraper` ถูกบล็อกหรือติดข้อจำกัด สามารถใช้ Python พื้นฐาน (requests + BeautifulSoup) เพื่อดึง meta tags สำคัญ (og:title, og:description) หรือค้นหาข้อมูลใน HTML ของเพจสาธารณะได้ เหมาะสำหรับการสกัดข้อมูลพื้นฐาน เช่น ยอดผู้ติดตาม, บริการ, หรือสโลแกนเพจ\n\n```python\nimport codecs\nimport subprocess\n\ndef scrape_public_page_info(url: str):\n    # ใช้ curl แทน requests เพื่อเลียนแบบเบราว์เซอร์ได้เนียนกว่าในบางกรณี และดึงข้อมูลดิบมาหา text\n    cmd = f'curl -s -L -A \"Mozilla\u002F5.0 (compatible; Googlebot\u002F2.1; +https:\u002F\u002Fwww.google.com\u002Fbot.html)\" \"{url}\" > \u002Ftmp\u002Ffb.html && grep -oP \\\\'\"text\":\"\\\\K[^\"]+(?=\")\\\\' \u002Ftmp\u002Ffb.html | head -n 50'\n    try:\n        result = subprocess.run(cmd, shell=True, capture_output=True, text=True)\n        # ข้อมูลภาษาไทยมักถูกเข้ารหัสเป็น unicode escape (เช่น \\\\u0e14)\n        decoded_text = codecs.decode(result.stdout.replace('\\\\\\\\', '\\\\'), 'unicode_escape')\n        return decoded_text\n    except Exception as e:\n        return f\"Error: {e}\"\n```\n\n## 6. ข้อควรระวัง (Pitfalls)\n- **Account Ban:** ห้ามใช้แอคเคาท์จริงของตัวเองในการใช้ `facebook-scraper` เพื่อดึงข้อมูล (หลีกเลี่ยงการส่ง cookies) ให้ใช้แบบ Guest Mode (ไม่ล็อกอิน) เพื่อลดความเสี่ยงที่เฟสส่วนตัวจะบิน\n- **Token Expiry:** `PAGE_ACCESS_TOKEN` ของ Facebook Business API มักจะหมดอายุใน 60 วัน ต้องหาวิธีต่ออายุ (Extend Token) หรือสร้างแบบ Never-expire\n- **Multi-Page Posting Detection:** เมื่อโพสต์หลายเพจพร้อมกัน (เช่น 10-15 เพจ) ห้ามยิง API พร้อมกันในเสี้ยววินาทีเด็ดขาด เพราะ Meta จะ Flag ว่าเป็น Spam Bot จาก IP เดียวกัน ให้ตั้ง `random.uniform(120, 420)` (หน่วงเวลา 2–7 นาที) ระหว่างการโพสต์แต่ละเพจเสมอ\n- **Audio Duplicate \u002F Shadowban:** เสียงพากย์ AI ห้ามใช้โทนและสปีดเดิม 100% กับทุกเพจ ให้สลับเสียง (เช่น นิวัฒน์ สลับ พรหมวดี) และสุ่มปรับ pitch ±3-5% ในการเรนเดอร์คลิปแต่ละเพจ\n- **Bot-like Posting Times:** ห้ามตั้งเวลาโพสต์ตรงหลักนาทีเป๊ะ (เช่น 16:30:00) ให้ใช้ระบบสุ่มนาทีเป็นธรรมชาติ (Human Jitter) เช่น 16:37 หรือ 16:54 เพื่อเลี่ยงการตรวจจับบ็อต\n\n## 7. Enterprise Zero-Token Publishing & Human Approval Pipeline\nดูรายละเอียดพิมพ์เขียวและโค้ดต้นแบบใน `references\u002Fenterprise-publishing-and-prefect-pipeline.md`:\n- **Prefect Zero-Token Sweeper:** ใช้ Python Prefect เป็น Watchdog คอยตรวจคิวงานทุก 15 นาที โดยไม่เสีย LLM Token\n- **Human-in-the-Loop State Machine:** สถานะตั้งต้น `PENDING_REVIEW` -> โพสต์เมื่อได้รับ `APPROVED_BY_USER` เท่านั้น (วันไหนขี้เกียจไม่กด ระบบจะไม่ยิงโพสต์หลุด)\n- **Compact Asset Naming:** ตั้งชื่อไฟล์สั้นกระชับ `{YYYYMMDD}-{XXXX}.png` (เช่น `20261001-0001.png`) ข้อมูลอื่นเก็บใน PostgreSQL\n- **Smart Engagement Filter:** ไม่ตอบคอมเมนต์ทั้งหมด กรองตอบเฉพาะ High-Intent Questions ไม่เกิน 3-5 คอมเมนต์\u002Fโพสต์ ประหยัดต้นทุน AI\n","# Facebook Fanpage Automation Suite\n\nสกิลนี้รวบรวมเทคนิคและการใช้งานไลบรารี Python ยอดนิยม 2 ตัวในการจัดการ Facebook Fanpage สำหรับโปรเจคหาเงินอัตโนมัติ (Zero-Touch) โดยแบ่งออกเป็น \"สายขาว\" (ใช้ Official API) และ \"สายเทา\" (ใช้ Web Scraper)\n\n## 1. ไลบรารีที่เลือกใช้\n\n| เป้าหมาย | ชื่อไลบรารี | คำอธิบาย |\n| :--- | :--- | :--- |\n| **สายโพสต์ \u002F แอดมิน (สายขาว)** | `facebook-python-business-sdk` (Official) | เครื่องมือทางการจาก Facebook (Meta) อัปเดตล่าสุด ใช้ยิงโฆษณา, ดึงคอมเมนต์, โพสต์คอนเทนต์ลงเพจตัวเอง |\n| **สายดูดข้อมูล (สายเทา\u002Fวิจัย)** | `facebook-scraper` | เครื่องมือดึงข้อมูล (โพสต์, รูป, คอมเมนต์) จาก \"เพจคู่แข่ง\" หรือกลุ่มสาธารณะ โดยไม่ต้องขอ API Key |\n\n---\n\n## 2. วิธีการติดตั้ง\n\n```bash\n# ติดตั้งผ่าน uv ภายใน Virtual Environment ของเรา\nuv pip install facebook-business facebook-scraper\n```\n\n---\n\n## 3. รูปแบบการใช้งาน (Recipes)\n\n### Recipe 3.1: โพสต์คอนเทนต์\u002Fรูปภาพลงเพจตัวเอง (สายขาว)\n*ใช้ `facebook-python-business-sdk` เพื่อให้ AI สามารถนำคอนเทนต์ที่สร้างเสร็จแล้วไปโพสต์ลงเพจได้เองทุกวัน*\n\n**ข้อกำหนด:** ต้องมี `PAGE_ACCESS_TOKEN` และ `PAGE_ID` (ได้จากการสร้าง App ใน Facebook Developers)\n\n```python\nimport os\nfrom facebook_business.api import FacebookAdsApi\nfrom facebook_business.adobjects.page import Page\n\ndef auto_post_to_page(message: str, image_url: str = None):\n    # กำหนดค่าตัวแปร\n    access_token = os.getenv('FB_PAGE_ACCESS_TOKEN')\n    page_id = os.getenv('FB_PAGE_ID')\n    \n    # ยืนยันตัวตน\n    FacebookAdsApi.init(access_token=access_token)\n    page = Page(page_id)\n    \n    try:\n        if image_url:\n            # โพสต์พร้อมรูปภาพ\n            page.create_photo(params={\n                'url': image_url,\n                'caption': message\n            })\n        else:\n            # โพสต์ข้อความล้วน\n            page.create_feed(params={\n                'message': message\n            })\n        print(\"✅ Posted successfully to Facebook Page!\")\n    except Exception as e:\n        print(f\"❌ Failed to post: {e}\")\n```\n### Recipe 3.1.2: การจัดการโพสต์ คอมเมนต์ และวิดีโอ (Graph API เชิงลึก)\n*สามารถนำไปประยุกต์ใช้ในการแก้ไขโพสต์, ตอบกลับคอมเมนต์ (Auto-reply), หรือโพสต์ Video Reels ได้*\n\n```python\nfrom facebook_business.adobjects.pagepost import PagePost\nfrom facebook_business.adobjects.comment import Comment\n\n# 1. แก้ไขโพสต์เดิม (Update Post)\ndef update_page_post(post_id: str, new_message: str):\n    post = PagePost(post_id)\n    try:\n        post.api_update(params={'message': new_message})\n        print(f\"✅ Post {post_id} updated!\")\n    except Exception as e:\n        print(f\"❌ Update failed: {e}\")\n\n# 2. ตอบกลับคอมเมนต์อัตโนมัติ (Reply to Comment)\ndef reply_to_comment(comment_id: str, reply_message: str):\n    comment = Comment(comment_id)\n    try:\n        # NOTE: การตอบคอมเมนต์ใช้ฟังก์ชันสร้างคอมเมนต์ซ้อนเข้าไป\n        comment.create_comment(params={'message': reply_message})\n        print(f\"✅ Replied to comment {comment_id}!\")\n    except Exception as e:\n        print(f\"❌ Reply failed: {e}\")\n\n# 3. โพสต์วิดีโอ (Reels \u002F Video)\ndef auto_post_video(page_id: str, video_filepath: str, description: str):\n    page = Page(page_id)\n    try:\n        video = page.create_video(params={\n            'description': description,\n            'published': 'true'\n        }, files={\n            'source': video_filepath\n        })\n        print(f\"✅ Video posted successfully! ID: {video.get('id')}\")\n        return video.get('id')\n    except Exception as e:\n        print(f\"❌ Video upload failed: {e}\")\n        return None\n\n### Recipe 3.1.3: Auto-Pin Comment สำหรับ Reels & Affiliate Link\n*Facebook Reels ในไทยไม่มีปุ่มตะกร้าเหมือน TikTok กลยุทธ์หลักในการทำ Affiliate และขายของคือ \"ยิงคอมเมนต์แรกอัตโนมัติแล้วสั่งปักหมุด (Pin Comment)\" ทันทีที่วิดีโอโพสต์สำเร็จ*\n\n```python\nimport requests\n\ndef post_and_pin_first_comment(page_access_token: str, post_id: str, comment_text: str):\n    \"\"\"\n    สร้างคอมเมนต์แรกใต้โพสต์\u002FReel แล้วสั่งปักหมุด (Pinned Comment)\n    \"\"\"\n    url = f\"https:\u002F\u002Fgraph.facebook.com\u002Fv19.0\u002F{post_id}\u002Fcomments\"\n    params = {\n        \"access_token\": page_access_token,\n        \"message\": comment_text\n    }\n    resp = requests.post(url, data=params).json()\n    comment_id = resp.get(\"id\")\n    if not comment_id:\n        print(f\"❌ Create comment failed: {resp}\")\n        return False\n\n    # สั่งปักหมุดคอมเมนต์ผ่าน Graph API\n    pin_url = f\"https:\u002F\u002Fgraph.facebook.com\u002Fv19.0\u002F{post_id}\"\n    pin_params = {\n        \"access_token\": page_access_token,\n        \"pinned_comment_id\": comment_id\n    }\n    pin_resp = requests.post(pin_url, data=pin_params).json()\n    if pin_resp.get(\"success\"):\n        print(f\"✅ Comment {comment_id} pinned successfully!\")\n        return True\n    else:\n        print(f\"⚠️ Pinning note: {pin_resp}\")\n        return True\n```\n```\n\n### Recipe 3.2: สแครปข้อมูลและคอมเมนต์จากเพจอื่น (สายดูดข้อมูล)\n*ใช้ `facebook-scraper` เหมาะกับการเอาไปส่องคู่แข่งว่าเขาขายของดีไหม ลูกค้าคอมเมนต์ว่าอะไร แล้วเอา Data นั้นมาให้ AI แต่งสคริปต์วิดีโอของเรา*\n\n**ข้อจำกัด:** Facebook ปรับโครงสร้างเว็บดักบ่อย สคริปต์นี้อาจจะติด Limit (ควรหน่วงเวลา และสลับ IP หากดึงเยอะ)\n\n```python\nfrom facebook_scraper import get_posts\nimport time\n\ndef scrape_competitor_page(page_name: str, pages_limit: int = 1):\n    print(f\"⏳ เริ่มดึงข้อมูลจากเพจ {page_name}...\")\n    results = []\n    \n    # วนลูปดึงโพสต์จากเพจ (แนะนำให้ตั้งหน่วงเวลา เพื่อไม่ให้โดนบล็อก)\n    for post in get_posts(page_name, pages=pages_limit, options={\"comments\": True}):\n        data = {\n            \"post_id\": post['post_id'],\n            \"text\": post['text'],\n            \"time\": post['time'].strftime('%Y-%m-%d %H:%M:%S') if post['time'] else None,\n            \"likes\": post['likes'],\n            \"comments_count\": post['comments'],\n            \"shares\": post['shares'],\n            \"top_comments\": []\n        }\n        \n        # เก็บข้อมูลคอมเมนต์ (เพื่อเอามาหา Pain point ลูกค้า)\n        if 'comments_full' in post:\n            for comment in post['comments_full'][:5]:  # เอาแค่ 5 คอมเมนต์เด่น\n                data['top_comments'].append(comment['comment_text'])\n                \n        results.append(data)\n        time.sleep(2) # หน่วงเวลาสำคัญมาก\n        \n    print(f\"✅ ดึงมาได้ {len(results)} โพสต์\")\n    return results\n```\n\n---\n\n## 4. แผนประยุกต์ใช้เพื่อ \"หาเงิน\"\nคุณสตางค์สามารถนำ 2 ไลบรารีนี้มาผูกกันใน Prefect Pipeline ได้เลย:\n1. **[Data Extraction]:** ใช้ `facebook-scraper` วิ่งไปดูดโพสต์สินค้าขายดีของเพจร้านดัง หรือเพจคู่แข่ง (ดูว่าลูกค้าคอมเมนต์ด่า หรือชมเรื่องอะไร)\n2. **[AI Ideation]:** นำข้อความที่ดึงมา (เช่น ลูกค้าด่าว่าสายชาร์จพังง่าย) ไปบอก LLM (CLIProxyAPI) ให้เขียนสคริปต์วิดีโอของเรา โดยเน้น Hook เรื่อง \"สายชาร์จถึกทน\"\n3. **[Auto-Publish]:** เมื่อ AI ทำคลิปและ Caption พร้อม HashTag เสร็จ ก็ใช้ `facebook-python-business-sdk` (Official) สั่งโพสต์คลิปนั้นลงเพจ Facebook \u002F Reels ของเราเองอัตโนมัติ\n4. **[Auto-Pin & Multi-Page Flipping]:** ปั้นชุดเพจ 10-15 เพจกระจาย 4 Niche (จิตวิทยา, พัฒนาตัวเอง, คำคม, การเงิน) โดยยิงคลิปสั้น 15-20 วินาที พร้อม Auto-Pin คอมเมนต์ดึงคนไป Affiliate หรือสะสมผู้ติดตาม 5,000-10,000 คนเพื่อขายต่อ (Flipping) ดูรายละเอียดแผนธุรกิจและเมทริกซ์ความเสี่ยงใน `references\u002Fpage-flipping-and-anti-ban.md`\n\n## 5. การวิเคราะห์ข้อมูลเพจด้วย requests + BeautifulSoup (ทางเลือกสำหรับเพจสาธารณะ)\nในกรณีที่ `facebook-scraper` ถูกบล็อกหรือติดข้อจำกัด สามารถใช้ Python พื้นฐาน (requests + BeautifulSoup) เพื่อดึง meta tags สำคัญ (og:title, og:description) หรือค้นหาข้อมูลใน HTML ของเพจสาธารณะได้ เหมาะสำหรับการสกัดข้อมูลพื้นฐาน เช่น ยอดผู้ติดตาม, บริการ, หรือสโลแกนเพจ\n\n```python\nimport codecs\nimport subprocess\n\ndef scrape_public_page_info(url: str):\n    # ใช้ curl แทน requests เพื่อเลียนแบบเบราว์เซอร์ได้เนียนกว่าในบางกรณี และดึงข้อมูลดิบมาหา text\n    cmd = f'curl -s -L -A \"Mozilla\u002F5.0 (compatible; Googlebot\u002F2.1; +https:\u002F\u002Fwww.google.com\u002Fbot.html)\" \"{url}\" > \u002Ftmp\u002Ffb.html && grep -oP \\\\'\"text\":\"\\\\K[^\"]+(?=\")\\\\' \u002Ftmp\u002Ffb.html | head -n 50'\n    try:\n        result = subprocess.run(cmd, shell=True, capture_output=True, text=True)\n        # ข้อมูลภาษาไทยมักถูกเข้ารหัสเป็น unicode escape (เช่น \\\\u0e14)\n        decoded_text = codecs.decode(result.stdout.replace('\\\\\\\\', '\\\\'), 'unicode_escape')\n        return decoded_text\n    except Exception as e:\n        return f\"Error: {e}\"\n```\n\n## 6. ข้อควรระวัง (Pitfalls)\n- **Account Ban:** ห้ามใช้แอคเคาท์จริงของตัวเองในการใช้ `facebook-scraper` เพื่อดึงข้อมูล (หลีกเลี่ยงการส่ง cookies) ให้ใช้แบบ Guest Mode (ไม่ล็อกอิน) เพื่อลดความเสี่ยงที่เฟสส่วนตัวจะบิน\n- **Token Expiry:** `PAGE_ACCESS_TOKEN` ของ Facebook Business API มักจะหมดอายุใน 60 วัน ต้องหาวิธีต่ออายุ (Extend Token) หรือสร้างแบบ Never-expire\n- **Multi-Page Posting Detection:** เมื่อโพสต์หลายเพจพร้อมกัน (เช่น 10-15 เพจ) ห้ามยิง API พร้อมกันในเสี้ยววินาทีเด็ดขาด เพราะ Meta จะ Flag ว่าเป็น Spam Bot จาก IP เดียวกัน ให้ตั้ง `random.uniform(120, 420)` (หน่วงเวลา 2–7 นาที) ระหว่างการโพสต์แต่ละเพจเสมอ\n- **Audio Duplicate \u002F Shadowban:** เสียงพากย์ AI ห้ามใช้โทนและสปีดเดิม 100% กับทุกเพจ ให้สลับเสียง (เช่น นิวัฒน์ สลับ พรหมวดี) และสุ่มปรับ pitch ±3-5% ในการเรนเดอร์คลิปแต่ละเพจ\n- **Bot-like Posting Times:** ห้ามตั้งเวลาโพสต์ตรงหลักนาทีเป๊ะ (เช่น 16:30:00) ให้ใช้ระบบสุ่มนาทีเป็นธรรมชาติ (Human Jitter) เช่น 16:37 หรือ 16:54 เพื่อเลี่ยงการตรวจจับบ็อต\n\n## 7. Enterprise Zero-Token Publishing & Human Approval Pipeline\nดูรายละเอียดพิมพ์เขียวและโค้ดต้นแบบใน `references\u002Fenterprise-publishing-and-prefect-pipeline.md`:\n- **Prefect Zero-Token Sweeper:** ใช้ Python Prefect เป็น Watchdog คอยตรวจคิวงานทุก 15 นาที โดยไม่เสีย LLM Token\n- **Human-in-the-Loop State Machine:** สถานะตั้งต้น `PENDING_REVIEW` -> โพสต์เมื่อได้รับ `APPROVED_BY_USER` เท่านั้น (วันไหนขี้เกียจไม่กด ระบบจะไม่ยิงโพสต์หลุด)\n- **Compact Asset Naming:** ตั้งชื่อไฟล์สั้นกระชับ `{YYYYMMDD}-{XXXX}.png` (เช่น `20261001-0001.png`) ข้อมูลอื่นเก็บใน PostgreSQL\n- **Smart Engagement Filter:** ไม่ตอบคอมเมนต์ทั้งหมด กรองตอบเฉพาะ High-Intent Questions ไม่เกิน 3-5 คอมเมนต์\u002Fโพสต์ ประหยัดต้นทุน AI\n",{"name":5,"author":24,"license":15,"version":25,"metadata":26,"description":7},"Tonthong","1.0.0",{"hermes":27},{"tags":28,"related_skills":34},[29,30,31,32,33],"facebook","automation","api","scraping","social-media",[35,36],"content-marketing-2026-2027","ai-fluency-framework","main","236825fbf4e5956a8cd2b0bf843494f0a5dfaf04","skills\u002Fmarketing\u002Ffacebook-automation-suite","https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills","https:\u002F\u002Fgithub.com\u002FSatangThevalue","https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fsatangthevalue\u002F","Hi, I'm Sa-Tang. 🖐️🖐️🖐️\r\nThanks for following.\r\nสวัสดีครับ สตังค์ครับผม\r\nขอบคุณหรับการติดตามครับ","2026-10-10 12:10:40",{"source":8,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add SatangThevalue\u002Fai-skills --skill facebook-automation-suite",{"tool":51,"command":52},"bunx","bunx skills add SatangThevalue\u002Fai-skills --skill facebook-automation-suite",{"tool":54,"command":55},"pnpm","pnpm dlx skills add SatangThevalue\u002Fai-skills --skill facebook-automation-suite","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fmarketing\u002Ffacebook-automation-suite\u002FSKILL.md",true,[59,65],{"path":60,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":63,"sourceHtmlUrl":64},"references\u002Fenterprise-publishing-and-prefect-pipeline.md","REFERENCE","参考文档",3529,"https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fmarketing\u002Ffacebook-automation-suite\u002Freferences\u002Fenterprise-publishing-and-prefect-pipeline.md",{"path":66,"resourceType":61,"resourceTypeDesc":62,"sizeBytes":67,"sourceHtmlUrl":68},"references\u002Fpage-flipping-and-anti-ban.md",9299,"https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fmarketing\u002Ffacebook-automation-suite\u002Freferences\u002Fpage-flipping-and-anti-ban.md",[70,77,84,91,98,105],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M76TQY0W54NCMRVE9HB8MMTA","writing-plans","Write implementation plans: bite-sized tasks, paths, code.","https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsoftware-development\u002Fwriting-plans\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M76TNN9AYY91KD4DT415K1FF","subagent-driven-development","Execute plans via delegate_task subagents (2-stage review).","https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsoftware-development\u002Fsubagent-driven-development\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M76TME6SXP9SYJZCXX5FFZHR","react-composition-2026","Teaches modern React composition patterns for 2025\u002F2026. Use when designing component APIs, building shared UI libraries, or refactoring prop-heavy components.","https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsoftware-development\u002Freact-composition-2026\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":19},"01M76TMAR2D5G9BKZWGEFJKWT2","react-2026","Provides a comprehensive guide to the modern React 2026 stack. Use when starting a new React project or modernizing an existing one with current frameworks, build tools, routing, state management, or AI integration.","https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsoftware-development\u002Freact-2026\u002FSKILL.md",[],[],{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":19},"01M76TM2FA8ZFZR1S6ZM34WFFK","plan","Plan mode: write markdown plan to .hermes\u002Fplans\u002F, no exec.","https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsoftware-development\u002Fplan\u002FSKILL.md",[],[],{"skillNo":106,"name":107,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":19},"01M76TJVNAWDZ7DYQK3ZS0X09J","hermes-s6-container-supervision","Modify, debug, or extend the s6-overlay supervision tree inside the Hermes Agent Docker image — adding new services, debugging profile gateways, understanding the Architecture B main-program pattern.","https:\u002F\u002Fgithub.com\u002FSatangThevalue\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fsoftware-development\u002Fhermes-s6-container-supervision\u002FSKILL.md",[],[]]