NODE js problem

Support
  • i m running script on visual studio works fine, i have problem addin it in BAS node. i add node-fetch and still not working

    import fetch from 'node-fetch';
    
    // Replace these values with your actual page access token and page ID
    const pageAccessToken = 'OWZBLIV1BjDW9';
    const pageId = '23713142828178';
    const message = 'This is a test post from blabla';
    
    // Facebook Graph API endpoint for posting to a page's feed
    const url = `https://graph.facebook.com/${pageId}/feed`;
    
    // Data to be sent in the POST request
    const data = {
        message: message,
        access_token: pageAccessToken
    };
    
    // Function to post to Facebook
    async function postToFacebook() {
        try {
            const response = await fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            });
            const result = await response.json();
            if (result.id) {
                console.log('Post created successfully!', result);
            } else {
                console.error('Error creating post:', result);
            }
        } catch (error) {
            console.error('Error:', error);
        }
    }
    
    // Call the function to post to Facebook
    postToFacebook();
    
    

    any advices ?

  • @mak0ni said in NODE js problem:

    import fetch from 'node-fetch

    
    const {default: fetch } = await import("node-fetch")
    
  • @UserTrue said in NODE js problem:

    const {default: fetch } = await import("node-fetch")

    it works thank you

  • 0 Votes
    2 Posts
    473 Views
  • reCaptcha Checkbox problem

    Support
    0 Votes
    5 Posts
    835 Views
  • Hcapctha Problem, HELP?

    Support
    0 Votes
    6 Posts
    856 Views
  • 0 Votes
    1 Posts
    653 Views
  • Regex Problem

    Support
    0 Votes
    3 Posts
    1301 Views