I'm still developping a Spotify App, but I thinkg there is some bug in the API and they report it as a bug for me.
I make then the test with the tutorial app using the function "Get songs from a playlist URL", they are in the tutorial using also the callback function like this
var pl = models.Playlist.fromURI(playlist_url, function(playlist)
But even using the Callback function on first load there is some null value.
With my own playlist, I don't have the issue but with playlist from other users I got the issue.
Does anybody else get the issue ? Is there a way to report API bug ?
For those who want to test my playlist: http://open.spotify.com/user/gpsnail/playlist/6qhk1FhYKwyanNAu91GftW
The Spotify Apps API 0.X is not longer supported. It might be the case that there was a bug and the data was being rendered before it was actually fetched. I would recommend you to use the newer version of the API, in which you can fetch the contents of a playlist doing:
require(['$api/models'], function(models) {
var playlistURI = 'spotify:user:gpsnail:playlist:6qhk1FhYKwyanNAu91GftW';
models.Playlist.fromURI(playlistURI)
.load('tracks')
.done(function(p) {
p.tracks.snapshot()
.done(
function(snapshot) {
for (var i = 0, l = snapshot.length; i < l; i++) {
var track = snapshot.get(i);
// we print out some basic data from the track
console.log(track.uri, track.name);
}
})
.fail(
function(){
console.error('Error retrieving snapshot');
});
})
.fail(function(){
console.error('Error retrieving playlist information');
});
});
There is more information about how to upgrade to the upgrade guide.
Related
I am trying to pass the Microsoft Cognitive services facial API an image which the user has uploaded. The image is available on the server in the uploads folder.
Microsoft is expecting the image to be 'application/octet-stream' and passed as binary data.
I am currently unable to find a way to pass the image to the API that is satisfactory for it to be accepted and keep receiving "decoding error, image format unsupported". As far as im aware the image must be uploaded in blob or file format but being new to NodeJs im really unsure on how to achieve this.
So far i have this and have looked a few options but none have worked, the other options i tried returned simmilar errors such as 'file too small or large' but when ive manually tested the same image via Postman it works fine.
image.mv('./uploads/' + req.files.image.name , function(err) {
if (err)
return res.status(500).send(err);
});
var encodedImage = new Buffer(req.files.image.data, 'binary').toString('hex');
let addAPersonFace = cognitive.addAPersonFace(personGroupId, personId, encodedImage);
addAPersonFace.then(function(data) {
res.render('pages/persons/face', { data: data, personGroupId : req.params.persongroupid, personId : req.params.personid} );
})
The package it looks like you're using, cognitive-services, does not appear to support file uploads. You might choose to raise an issue on the GitHub page.
Alternative NPM packages do exist, though, if that's an option. With project-oxford, you would do something like the following:
var oxford = require('project-oxford'),
client = new oxford.Client(YOUR_FACE_API_KEY),
uuid = require('uuid');
var personGroupId = uuid.v4();
var personGroupName = 'my-person-group-name';
var personName = 'my-person-name';
var facePath = './images/face.jpg';
// Skip the person-group creation if you already have one
console.log(JSON.stringify({personGroupId: personGroupId}));
client.face.personGroup.create(personGroupId, personGroupName, '')
.then(function(createPersonGroupResponse) {
// Skip the person creation if you already have one
client.face.person.create(personGroupId, personName)
.then(function(createPersonResponse) {
console.log(JSON.stringify(createPersonResponse))
personId = createPersonResponse.personId;
// Associate an image to the person
client.face.person.addFace(personGroupId, personId, {path: facePath})
.then(function (addFaceResponse) {
console.log(JSON.stringify(addFaceResponse));
})
})
});
Please update to version 0.2.0, this should work now.
I am using youtube-node npm to find out all the video list. The documentation is on the link https://www.npmjs.com/package/youtube-node.
But I want that my search only show result of a specific channel i.e if I search hello, then it only give result of AdeleVEVO YouTube channel.
I cant find suitable documentation for that. I don't want to use oauth credentials, I only want to use youtube-node npm.
In package doc you have a sample search, make sure you include in the params parameter an object with the values you want, in your case see in youtube api doc that you need to specify the channelId. Try this way:
var YouTube = require('youtube-node');
var youTube = new YouTube();
youTube.setKey('AIzaSyB1OOSpTREs85WUMvIgJvLTZKye4BVsoFU');
youTube.search('World War z Trailer', 2, {channelId: <string value of the channelId>}, function(error, result) {
if (error) {
console.log(error);
}
else {
console.log(JSON.stringify(result, null, 2));
}
})
;
If you are the owner of the channel, you can use the forMine parameter of the YouTube API for this. Setting this parameter will limit the search to the authorized user's videos. Below is a sample from the official documentation.
IMPORTANT NOTE: Do not use the youtube-node module for this, specifically because--in my experience at least--the addParam() function does not reliably add parameters to the request (e.g., in my code I called youtube_node.addParam('safeSearch', 'strict');, but restricted videos would still be returned in the results.)
Instead, use the YouTube Data API directly as shown in this quickstart example.
// Sample nodejs code for search.list
function searchListMine(auth, requestData) {
var service = google.youtube('v3');
var parameters = removeEmptyParameters(requestData['params']);
parameters['auth'] = auth;
service.search.list(parameters, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
console.log(response);
});
}
//See full code sample for authorize() function code.
authorize(JSON.parse(content), {'params': {'maxResults': '25',
'forMine': 'true',
'part': 'snippet',
'q': 'fun',
'type': 'video'}}, searchListMine);
This is my first post here so please don't get mad if my formatting is a bit off ;-)
I'm trying to develop a backend solution using Azure mobile apps and node.js for server side scripts. It is a steep curve as I am new to javaScript and node.js coming from the embedded world. What I have made is a custom API that can add users to a MSSQL table, which is working fine using the tables object. However, I also need to be able to delete users from the same table. My code for adding a user is:
var userTable = req.azureMobile.tables('MyfUserInfo');
item.id = uuid.v4();
userTable.insert(item).then( function (){
console.log("inserted data");
res.status(200).send(item);
});
It works. The Azure node.js documentation is really not in good shape and I keep searching for good example on how to do simple things. Pretty annoying and time consuming.
The SDK documentation on delete operations says it works the same way as read, but that is not true. Or I am dumb as a wet door. My code for deleting looks like this - it results in exception
query = queries.create('MyfUserInfo')
.where({ id: results[i].id });
userTable.delete(query).then( function(delet){
console.log("deleted id ", delet);
});
I have also tried this and no success either
userTable.where({ id: item.id }).read()
.then( function(results) {
if (results.length > 0)
{
for (var i = 0; i < results.length; i++)
{
userTable.delete(results[i].id);
});
}
}
Can somebody please point me in the right direction on the correct syntax for this and explain why it has to be so difficult doing basic stuff here ;-) It seems like there are many ways of doing the exact same thing, which really confuses me.
Thanks alot
Martin
You could issue SQL in your api
var api = {
get: (request, response, next) => {
var query = {
sql: 'UPDATE TodoItem SET complete=#completed',
parameters: [
{ name: 'completed', value: request.params.completed }
]
};
request.azureMobile.data.execute(query)
.then(function (results) {
response.json(results);
});
}};
module.exports = api;
That is from their sample on GitHub
Here is the full list of samples to take a look at
Why are you doing a custom API for a table? Just define the table within the tables directory and add any custom authorization / authentication.
I'm trying to geolocate users in a Spotify app. However, I only get back garbage location data from Spotify. The promise doesn't fail, but return an accuracy of -1 and lat/lon of 200/200. Is there some permission that I'm missing? Has anyone successfully integrated this?
The code:
require([
'$api/models',
'$api/location',
'$views/image#Image',
'$views/list#List'
], function(models, Location, Image, List) {
'use strict';
var loc = Location.Location.query();
loc.load('latitude', 'longitude', 'accuracy').done(function() {
console.log('Found you!', loc.latitude, loc.longitude);
window.theLocation = loc;
}).fail(function(loc, error) {
console.log("I failed!", error)
});
...
The console:
Found you! 200 200
theLocation.accuracy
-1
theLocation.latitude
200
theLocation.longitude
200
EDIT: See my follow-up question here: What method(s) can I use for geolocation through a Spotify app?
Unfortunately, this isn't supported and shouldn't be in the documentation. We're working on the documentation and this will be removed once it's updated.
I read in another thread (http://stackoverflow.com/questions/9474011/showing-a-album-cover)
that the:
Please don't use any of the sp. APIs - they're private and going away soon.
My question is, what is the correct way of getting album and/or playlist information from the API?
I'm currently playing around with this:
sp.core.getMetadata(uri, {
onSuccess: function(uri) {
// Success
},
onFailure: function() {
// Failure
}
});
I guess this is private and shouldn't be used right? Instead I should get the info from the models.* object? If not, is there another preferred method of dealing with this?
Always use models. Documentation can be found here.
For example:
var sp = getSpotifyApi(1);
var models = sp.require('sp://import/scripts/api/models');
var a = models.Album.fromURI("spotify:album:5zyS3GEyL1FmDWgVXxUvj7", function(album) {
console.log("Album loaded", album.name);
});