Spotify api recently played paging - spotify

When I'm fetching my listening history with this URL : https://api.spotify.com/v1/me/player/recently-played?limit=50
I'm getting a "next" attribute from the response to fetch the previous data.
When I'm fetching API with this "next" url (i.e https://api.spotify.com/v1/me/player/recently-played?before=1557334757252&limit=50), it returns an empty tracks array.
I don't understand why I'm getting an empty array.
PS : I obviously listened to more than 50 songs

Returns the most recent 50 tracks played by a user. Note that a track
currently playing will not be visible in play history until it has
completed. A track must be played for more than 30 seconds to be
included in play history.
Spotify stores 50 recent tracks information only. Since you already retrieved 50 records there is no use for using after or before cursor.Use limit which is not 50 then you can use the cursors.

Related

Spotify Webhooks?

Does the Spotify platform plan to offer any webhooks for third party developers to listen in to changes in user libraries, playlists or the player?
What are some known workarounds if webhooks don't exist?
There are no webhooks in the Web API and I think it will be quite a while before the feature is added https://github.com/spotify/web-api/issues/538
Playlists on Spotify are versioned by a snapshot_id. When you make an API request to get a playlist, one of the returned fields is snapshot_id, which identifies the playlist version. If you store this version ID for each playlist, you can check if the playlist has changed remotely since the last time you checked (the snapshot_id would change if so)
It's important to remember that any changes you make will also affect the snapshot_id. So you will need to:
Get the Playlist
Does your locally saved snapshot_id differ from the current one for the playlist?
If it does, maybe make some changes
After you make your changes, get the playlist again
Store the snapshot_id from the Get Playlist after you made your changes
I don't think snapshot_id is supported for a user's library - you can check a subset of the user's library to detect any additions (e.g. if the first 50 songs in the library haven't changed, then no new songs have been added, and you only had to make one API request instead of umpteen), but you will miss deletions from the rest of the library if you only do this. You can also check the count of songs in the library, which would tell you when songs have been added or deleted, except in the edge case where they add and delete the same number of songs. But this means they have added a song and checking the first 50 songs in the library would catch this.
You can poll for currently playing and recently played songs. If you want to track every song a user listens to, you can achieve this by polling Recently Played at least every 30 * 50 seconds (25 mins). 30 is the number of seconds it takes to listen to a song before Spotify records it as a Listen and 50 is the max number of recently played songs it will serve you.
To know when a track finished playing I set an await function to wait for the duration of that track, and then continue after thet
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
//start playing a track
let device_status = await spotifyApi.getMyCurrentPlaybackState().then(result =>{
return result.body;
})
let time_left = device_status.item.duration_ms - device_status.progress_ms;
await delay(time_left)
//whatever needs to be done after

Eventful API: Searching for events at a particular place

I'm searching for events at a particular place and also successfully retrieving all the events. But suppose I'm getting about 1500 events as "total_items" and the first page of response shows up the first 10 events.Then how could I reach to the remaining set of events, there isn't any "next page link".
And the most important question that are there any restrictions or upgradation plan for Eventful. Just because I was not able to find the required answers on their web portal. I'm posting it over here.
You are getting 10 events as default page size is 10 .If you want to change page size ,you can change it in your query.
http://api.eventful.com/rest/events/search?l=GREEN+BAY+WEST&page_size=100
In the above query it will return 100 events,you can get 100 events per page maximum.
If you want to go to next page,you can change page_number in your query.

nodejs facebook feeds with delay

i've written a batch in nodejs to get the feeds from a particular facebook user-id; the nodejs (version 0.10.33) code uses node module fb version 0.7.0 (https://www.npmjs.com/package/fb) .
the batch's request is scheduled every 5 minutes .
the facebook API response usually gives me back many feeds with a few minutes delay between the request's time and the created_at/updated_at feed values .
however sometimes i get some missing feeds that are visible in the user's page on the request's time.
after many requests and many hours i finally get those missing feeds but the strange thing is that their created_at/updated_at fields values are the same as their publishing time.
some idea ?
finally i found that the admin of a facebook page can decide to post his feeds in every date (past and future) he wants by the functions "RESCHEDULE" or "PROGRAMMED".
so, even if the feed is written now (call it time1), it appears on the user's page at the decided date (call it time2) ; the creation date on the page is time1 and the facebook's api for this feed returns created_at/updated_at=time1 .
when at time2 i launch my batch i get back created_at/updated_at=time1 for that feed : this is the final reason i often get a big delay between the feed's publishing date and the batch's request time.

Instagram: Get photos from a tag after a specified photo

I'm working on an instagram scraper for something and I'm trying to figure out if it's possible to get all photos for a tag that have an id or timestamp later than the last one I have.
The instagram API docs are useless in that they don't have any real info on pagination (which I presume I'll have to abuse).
Does anyone have any ideas?
I've been slogging through the Instagram API for the last couple of days so here's my 2 cents worth:
As far as I can see it if you call the api with /tags/tag-name/media/recent it only return a list if items. If the amount exceeds about 25 you have to make another request with the pagination value returned in the previous request.
In order to gain some control I am initially iterating through all images and storing the results (just the URL not the actual image) to a database. Now I can manipulate however I want. When I feel like updating (I'm doing it manually now but could be a cron job or use the real-time api) I re-read all the images, compare to what I have in my DB and add possible new images. My app then reads out the url and info from my DB (which btw is a heck of a lot faster than going through the instagram api, which will only return about 25 images per request - regardless of any 'count' parameter value you put in the request url) and displays it.
I am developing this for a client who is afraid of people posting nsfw or whatever pics using their dedicated hashtag (for a contest) - with the above set up I can offer them an interface where they can check and mark images that are then displayed in the app.
One thing to watch out for is when a user deletes his picture; you will have to find a way to check for this. Currently (since I'm lazy) I load all images and use jquery to check for an error loading the image. If there is one I delete the image from the DB (via ajax).
I'm not sure the pagination is going to help you: as far as I can see the pagination response has no relation to the id's of the actual image objects on each page - so theoretically a pagination id that jumps to a certain page (i.e. date) might not work tomorrow if enough images have been deleted in the mean time.
to get all images instead of latest 20, just append &count=-1 to your api call - it's that simple.
In either case, there is a timestamp on each json object - or if you prefer, you can use max_tag_id
check out my post here: there any way to show more than 20 photos of the instagram API?
* Update April 2014: count=-1 is no longer available.

libspotify API: number of albums is different when browsing the same artist

I'm trying to use the existing example browse.c to get the number of albums of an artist by given an artist uri. The return value of sp_artistbrowse_num_albums(browse) is different every time when I run the command browse spotify:artist:3fMbdgg4jU18AjLCKBhRSm. Why?
Do I understand correctly that the callback artistbrowse_complete_cb is invoked once only when browsing is complete, but callback metadata_updated is invoked whenever metadata is updated?
Thanks.
Do I understand correctly that the callback artistbrowse_complete_cb is invoked once only when browsing is complete, but callback metadata_updated is invoked whenever metadata is updated?
That's correct. As I've said before, metadata_updated means "some metadata has been updated somewhere", and there are more specific callbacks like artistbrowse_complete_cb for more targeted operations like artist browsing.
As to why it keeps changing — it's a bit odd as the number of albums for an artist doesn't normally oscillate much, but albums can be added and removed on a daily basis. It's best to just accept what you're told and keep your UI up-to-date.

Resources