Canva automation and google drive embeds
import requests
Your Canva API key
api_key = 'YOUR_CANVA_API_KEY'
design_id = 'YOUR_DESIGN_ID' # Replace with your actual whiteboard design ID
page_id = 'YOUR_PAGE_ID' # Replace with your specific page ID within the whiteboard
Endpoint to update a specific page in the design
url = f"https://api.canva.com/v1/designs/{design_id}/pages/{page_id}/elements"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
List of YouTube video URLs and their positions
urls_and_positions = [
Add more URLs and positions as needed
]
Elements array to hold the embed and rectangle elements
elements = []
for item in urls_and_positions:
url = item["url"]
x = item["x"]
y = item["y"]# Rectangle element rectangle_element = { "type": "rectangle", "position": {"x": x, "y": y}, "size": {"width": 600, "height": 400}, "background": {"color": "#ffffff"}, "border": {"width": 2, "color": "#000000"} } elements.append(rectangle_element) # Embed element embed_element = { "type": "embed", "url": url, "position": {"x": x + 10, "y": y + 10}, # Slight offset for padding inside the rectangle "size": {"width": 580, "height": 380} } elements.append(embed_element)
Create the request payload
data = {
"elements": elements
}
Send the request to update the specific page
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
print("YouTube videos embedded successfully")
else:
print(f"Failed to embed videos: {response.json()}")
Imported from rifaterdemsahin.com · 2024