I’m stuck trying to get text from Figma and put it into Google Slides using Google Apps Script. My code goes through a loop but the API isn’t working right. Here’s what I’ve got so far:
yo, i think i kno what’s up. the api’s prolly givin u a diff structure than u expect. try console.loggin the figmaData to see what ur really gettin. also, ur findTextNodes function might miss some nested stuff. maybe try a more recursive approach? just some ideas, hope it helps!
I’ve encountered similar challenges when working with the Figma API. One thing that helped me was modifying the findTextNodes function to handle nested text nodes more effectively. Here’s what worked for me:
function findTextNodes(node, textNodes = []) {
if (node.type === 'TEXT') {
textNodes.push(node);
} else if (node.children) {
node.children.forEach(child => findTextNodes(child, textNodes));
}
return textNodes;
}
This approach ensures you’re capturing all text nodes, even those deeply nested within groups or frames. Also, make sure you’re handling API rate limits properly - I learned that the hard way when my script kept timing out on larger Figma files. Consider implementing a delay between API calls if you’re processing multiple pages or large amounts of data. Good luck with your project!
hey, i had a similar issue. try using node.characters instead of node.text to get the actual content. also, make sure ur api token has the right permissions. double-check ur file ID too. sometimes that can cause weird issues. hope this helps!
I’ve dealt with similar Figma API issues before. Your approach is sound, but there might be a few tweaks needed. First, ensure you’re using the correct node structure. Figma’s API can be tricky with nested components. Try logging the figmaData to console to verify the structure.
Another point: the flatMap method might not catch all text nodes in complex layouts. Consider a recursive function that traverses the entire node tree. Also, error handling is crucial. Wrap your API calls in try-catch blocks to gracefully handle any issues.
Lastly, if you’re dealing with a large Figma file, consider implementing pagination or chunking your requests to avoid timeouts. The Figma API has rate limits, so be mindful of those in your implementation.