Spaces:
Running
Running
Download 731ai/create_presentation.js from u11310019/interactive-multi-web: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/spaces/u11310019/interactive-multi-web/resolve/main/731ai/create_presentation.js
- Command line
-
hf download hf://spaces/u11310019/interactive-multi-web/731ai/create_presentation.js
-
curl -L -o create_presentation.js https://huggingface.co/spaces/u11310019/interactive-multi-web/resolve/main/731ai/create_presentation.js
2.3 kB
| process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | |
| const API_TOKEN = 'cnvcafJ1UNaqnjsluqojCmucVHpyYwkkk8i8ObbyhkQttk8U9df0092a'; | |
| const CLIENT_ID = 'OC-AZ-payfWKq48'; | |
| async function createPresentation() { | |
| console.log('正在向 Canva Connect API 發送請求以建立簡報...'); | |
| // POST https://api.canva.com/rest/v1/designs | |
| const url = 'https://api.canva.com/rest/v1/designs'; | |
| const payload = { | |
| design: { | |
| type: 'presentation', | |
| title: '731ai分享' | |
| } | |
| }; | |
| try { | |
| const response = await fetch(url, { | |
| method: 'POST', | |
| headers: { | |
| 'Authorization': `Bearer ${API_TOKEN}`, | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify(payload) | |
| }); | |
| const status = response.status; | |
| const text = await response.text(); | |
| console.log(`HTTP 狀態碼: ${status}`); | |
| console.log('回應內容:', text); | |
| if (response.ok) { | |
| const data = JSON.parse(text); | |
| console.log('\n✅ 成功建立簡報專案!'); | |
| console.log('專案 ID:', data.design?.id); | |
| console.log('專案標題:', data.design?.title); | |
| console.log('編輯/瀏覽網址:', data.design?.urls?.edit_url || data.design?.urls?.view_url); | |
| return data; | |
| } else { | |
| // 若包含某些特定格式問題,試著調整 payload 嘗試 | |
| console.log('如果標題不支援直接傳送在 design 物件內,嘗試備用格式...'); | |
| await tryAlternativePayload(); | |
| } | |
| } catch (error) { | |
| console.error('請求失敗:', error); | |
| } | |
| } | |
| async function tryAlternativePayload() { | |
| const url = 'https://api.canva.com/rest/v1/designs'; | |
| // 試嘗試僅 type: presentation 或 asset/folder 建立方式 | |
| const payload = { | |
| design: { | |
| type: 'presentation' | |
| }, | |
| title: '731ai分享' | |
| }; | |
| try { | |
| const response = await fetch(url, { | |
| method: 'POST', | |
| headers: { | |
| 'Authorization': `Bearer ${API_TOKEN}`, | |
| 'Content-Type': 'application/json' | |
| }, | |
| body: JSON.stringify(payload) | |
| }); | |
| const status = response.status; | |
| const text = await response.text(); | |
| console.log(`[備用請求] HTTP 狀態碼: ${status}`); | |
| console.log('[備用請求] 回應內容:', text); | |
| } catch (err) { | |
| console.error('備用請求失敗:', err); | |
| } | |
| } | |
| createPresentation(); | |