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.
Related
This is the screenshot of my Javascript codeThis is the screenshot of postman
app.get("/students/:id",async(req,res)=>{
try {
const _id=req.params.id;
const studentData=await Student.findById(_id);
console.log(studentData);
if(!studentData){
return res.status(404).send();
}else
res.send(studentData);
}
catch(err) {
res.send(err);
}
});
For this id case I am able to find the value in database.
But if I am using model.find({name:name}) as per screenshot ,I am getting some error in postman.Can anyone help me to solve the issue.
it seems you have two conflicting routes, from your code above I see you have a get route for /student/:id and from the screenshot you have another get route for /student/:name these two routes cannot exist together as express is going to pick the first one you defined.
I suggest changing them to /student/id/:id and /student/name/:name.
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 have been using Twitters search API (via the node-twitter module) and I am running into an issue with the attitude operator. I am looking to get both positive and negative tweets about a certain subject. Currently though they return identical results. Here is my code that calls the API.
// Add since ID for future requests
twitterSearchClient.search(
{'q' :'xmas+%3A%28',
'lang' : 'en',
'count' : 100,
'result_type': 'recent'},
function(error, result) {
if (error) {
console.log('Error: ' + (error.code ? error.code + ' ' + error.message : error.message));
}
if (result) {
var requestDetails = result.search_metadata;
var results = result.statuses;
var resultsLength = results.length;
var r;
var data;
var d;
console.log(resultsLength);
for (var i=0; i<resultsLength; i++) {
console.log(r.text);
}
}
}
);
As you can see I am using the fully urlencoded value like the example in the documentation. I have also tried using xmas+%3A) for positive and xmas+%3A( for negative but this returns a 401 unauthorised error for some reason.
Has anyone ran into this issue or has a solution.
If you have any future questions I will be happy to answer them
Thanks in advance.
Per twitter's docs
Please, make sure to URL encode these queries before making the request
When going to that url and typing in your search xmas :) I got this query
https://twitter.com/search?q=xmas%20%3A)
as you can see xmas :) = xmas%20%3A) and xmas :( ends up being
https://twitter.com/search?q=xmas%20%3A(
xmas :( = xmas%20%3A(
If you still do not get different results (you can compare the results to what get when doing the search on the link above) then it is not the query, but maybe how you are making the call. Will need additional information if that is the case.
In this case, have you tried not encoding your query? The client may well be encoding it on your behalf.
...
'q': 'xmas :(',
...
NOTE: You do not mention, or link to which twitter client (via npm?) that you are using.
I can't speak for your specific issues, when I search via the form on the site I do get different results, and the queries are URI encoded... When you are passing input to a remote query string, I would recommend using encodeURIComponent('xmas :)') for your input values, this will yield the most predictable results.
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.
I am trying nTwitter (nodejs v0.6.10) - I tried using the example code for searching twitter but I get the following error when trying the search function for the library (the keys I am using appear to be correct):
Cannot set property 'q' of null
Any ideas what might be causing this issue - stack trace is copied below (so is the code)?
//twit is instance of Twitter (with keys assigned in)
twit.search('nodejs', function(err, data) {
if (err) {
console.log('Twitter search failed!');
}
else {
console.log('Search results:');
console.dir(data);
}
});
at Object.merge (/opt/testDir/node/node_modules/ntwitter/lib/utils.js:9:18)
at Twitter.search (/opt/testDir/node/node_modules/ntwitter/lib/twitter.js:167:18)
at Object.search (/opt/testDir/node/projects/testApp/public/javascripts/nTwitterTest.js:13:6)
at nTwitterTestMediator (/opt/testDir/node/projects/testApp/app.js:1188:14)
at callbacks (/opt/testDir/node/projects/testApp/node_modules/express/lib/router/index.js:272:11)
at param (/opt/testDir/node/projects/testApp/node_modules/express/lib/router/index.js:246:11)
at pass (/opt/testDir/node/projects/testApp/node_modules/express/lib/router/index.js:253:5)
at Router._dispatch (/opt/testDir/node/projects/testApp/node_modules/express/lib/router/index.js:280:4)
at Object.handle (/opt/testDir/node/projects/testApp/node_modules/express/lib/router/index.js:45:10)
at next (/opt/testDir/node/projects/testApp/node_modules/connect/lib/http.js:201:15)
Pilot error - the settings on twitter were not updated (from read only to read-write-execute).
I switched to read & write (instead of read, write and execute) and the settings changed (this was due to my ignorance of twitter api's & permission levels).
I was able to post tweets as well as access the streaming API (with the code on the github page) with the read-write access level for the twitter app.
I am still unable to use the search feature (code below).
twit.search('nodejs', function(err, data) {
if (err) {
console.log('Twitter search failed!');
}
else {
console.log('Search results:');
console.dir(data);
}
});
Thanks
I had this problem as well. You are missing one parameter.
Try this:
twit.search('nodejs', {}, function(err, data){
I think this was an error in the original ntwitter documentation.
Pilot error - the settings on twitter were not updated (from read only to read-write-execute).
I switched to read & write (instead of read, write and execute) and the settings changed (this was due to my ignorance of twitter api's & permission levels).
I was able to post tweets as well as access the streaming API (with the code on the github page) with the read-write access level for the twitter app.
I am still unable to use the search feature (code below).
twit.search('nodejs', function(err, data) {
if (err) {
console.log('Twitter search failed!');
}
else {
console.log('Search results:');
console.dir(data);
}
});
Thanks.