export_ad_image_file
Download ad image files from Meta Ads campaigns to local directories for creative management and asset organization.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ad_id | Yes | ||
| meta_access_token | No | ||
| output_dir | No | ad_images |
Implementation Reference
- The handler for the 'export_ad_image_file' tool. It fetches the ad image using 'read_ad_image' and saves it to the specified directory.
async def export_ad_image_file( ad_id: str, meta_access_token: Optional[str] = None, output_dir: str = "ad_images", ) -> str: if not ad_id: return _json({"error": "No ad ID provided"}) image = await read_ad_image(ad_id=ad_id, meta_access_token=meta_access_token) if not isinstance(image, Image): return _json({"error": "Unexpected image response type"}) os.makedirs(output_dir, exist_ok=True) file_path = os.path.join(output_dir, f"{ad_id}.jpg") with open(file_path, "wb") as handle: handle.write(image.data) return _json({"filepath": file_path})