spotify-api / spotify-api.js

A complete wrapper for spotify web api for deno, node.js and the browser.
https://spotify-api.js.org
MIT License
214 stars 19 forks source link

Can't return track search result #15

Closed olivoreo closed 3 years ago

olivoreo commented 3 years ago

Hello! When creating my bot on Dialogflow using the Fulfillment Editor, I found that when using " const track = await spotify.tracks. search ()", the result is empty. Although the access token output works. Can you tell me what the problem is? Here is my code:

'use strict';

 const functions = require('firebase-functions');
 const admin = require('firebase-admin');
 admin.initializeApp();
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));

async function search(agent) {
const Spotify = require("spotify-api.js");
const Auth = new Spotify.Auth();

var token = await Auth.get({
    client_id: "<client_id>",
    client_secret: "<client_secret>",
}); 

  const { Client } = require("spotify-api.js"); 
  const spotify = new Client(token); 
  const track = await spotify.tracks.search("oh my god by alec benjamin"); 
  agent.add(token + ' ' + track);
}

  let intentMap = new Map();
  intentMap.set('Spotify', search);
  // intentMap.set('your intent name here', yourFunctionHandler);
  agent.handleRequest(intentMap);
});
scientific-dev commented 3 years ago

For some reasons the package is broken, we are working on it! We will release newer version soon asap! We will notify when its ready...

olivoreo commented 3 years ago

Okay, I'll be waiting! I already thought I made a mistake in the code.

scientific-dev commented 3 years ago

But incase if its real urgent you can do

npm i github:spotify-api/spotify-api.js

This one is beta version we are working on might have bugs

scientific-dev commented 3 years ago

We have updated our package now you can test your works! Only if any bugs reopen this issue! And make sure you are not using v5 because it has Axios security issues and a lot of bugs... Plus v5 has broken in code image where v6 is fixed in code image but half fixed.