5

While I am in a process of integrating Spotify API into Google Assistant app, implementing Account Linking,

getaddrinfo EAI_AGAIN api.spotify.com:443

This above error has been kept coming out in the console, although it seems to be working like nothing is wrong around API implementation. The access token is properly created and received and client and secret ids were filled without any typo. Also, I tested API calls on Spotify Console (https://developer.spotify.com/console/get-artist-albums/). No error was found. It fetched expected data from the Spotify server, so it should not be related to Account Linking and Spotify Server. The created code myself is below: I assume there is something wrong around spotify-web-api-node, node, npm, or firebase-functions?? I recently have done node versioning so I might did something wrong.

  • Node version: v7.9.0
  • spotify-web-api-node: ^4.0.0
  • firebase-functions: ^2.0.3
  • npm version: 6.4.1
  • Added engines: { "node": "8" } // this is in package.json to use asyn and await

app.intent(SomeIntent, async (conv, params) => {
    console.log('user info', JSON.stringify(conv.user));
    conv.ask('lets play'); //okay
    const access_token = conv.user.access.token || ''; // okay
    console.log('Your TOKEN information here: ' + access_token); // okay
    spotifyApi.setAccessToken(access_token); // should be set correctly
    let data = await findMusic(); // error in the findMusic func
    conv.ask('found this song。', data.name); //  so no data.name
});

function findMusic() {
    return spotifyApi.getArtistAlbums('43ZHCT0cAZBISjO8DG9PnE').then((data) => {
        console.log('artist song', data.body);
        return data.body; //this does not return because error is produced
    }).catch(err => {
        console.log('Something went wrong!', err);
        return err; // this error is WebapiError: getaddrinfo EAI_AGAIN api.spotify.com:443
    });
}

UPDATE

@Nick-Felker mentioned in the comment below that external calls are allowed only through paid plans. So this might be the solution (not proved to be working right now because I am not using a paid plan. The detailed explanation below is quoted from An answer comment from another StackOverflow post

The Spark plan allows outbound network requests only to Google-owned services. Inbound invocation requests are allowed within the quota. On the Blaze plan, Cloud Functions provides a perpetual free tier. The first 2,000,000 invocations, 400,000 GB-sec, 200,000 CPU-sec, and 5 GB of Internet egress traffic is provided for free each month. You are only charged on usage past this free allotment. Pricing is based on total number of invocations, and compute time. Compute time is variable based on the amount of memory and CPU provisioned for a function. Usage limits are also enforced through daily and 100s quotas. For more information, see Cloud Functions Pricing.

UPDATE

In my case, the above solution worked. Hope this article helps others!

Ryohei
  • 713
  • 2
  • 9
  • 20
  • 1
    `EAI_AGAIN` is a DNS lookup error!! More details can be found at https://stackoverflow.com/a/40182520/6611700 – riyaz-ali Nov 02 '18 at 04:19
  • @riyaz-ali thanks for the reply. I am doing ''npm install latest-version'' to see if that works. But does not seem to work.... What else do you think I should do – Ryohei Nov 02 '18 at 04:47
  • 3
    Are you using the Blaze plan for Firebase? Firebase blocks external network calls on the free tier. – Nick Felker Nov 02 '18 at 05:24
  • 1
    @NickFelker the current plan of Firebase is Spark, so yes it is a free plan. So you mean if I swtich to Blaze plan, you think this can be fixed? Then I will test this later when I switch to my another account. Also do you think there are some possible clues that point out this bug? – Ryohei Nov 02 '18 at 05:28
  • Yeah I looked through other articles and Firebase Price page, and people also mentioned that. https://stackoverflow.com/a/43645498/9363250 I will upvote your comment as soon as I test it. Thank you very much. – Ryohei Nov 02 '18 at 05:36
  • @NickFelker You were right. After I switched the plan to the paid plan, it worked. Big thanks. – Ryohei Nov 05 '18 at 01:53

1 Answers1

1

I got this error due to network problem. And solved when connected