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.
Related
I am implementing a movie search application; in which movies will be returned after clicking search.
In the result lists, user can give "like" to the movies displayed to them.
However, if the user selects to sort by like, the my sort function actually is sorting the "old" search result while some movie's number of like may be changed due to user input.
So, I would like to reload the pages so that the page will go back to the server to load new data and then do the sorting again.
May I know if there is a way to reload the pages by calling my current URL and then I add an extra param on the URL like (sort by no of like). So that I can know I should sort it by no of like in the server-side function
Or if there is a simple approach to deal with this case
Edit for better illustration
the search result is a list of movie
stage 1
1.
Titanic
like:3
2.
spiderman
like:3
stage 2 (user give a like to second one)
1.
Titanic
like:3
2.
spiderman
like:4 <----- no of like increased due to the user giving raising point)
stage 3 User suddenly wants to sort the results by no of like; then I sort the results on the fly.
1.
Titanic
like:3
2.
spiderman
like:3 <------ the results is not updated since the result is old
routing function I am using
router.push({
pathname: "/search",
query: {sort: sort}
)
but the reload is not clean. Component is still cached
[edit 2]
In each item in the result list, it is actually wrapped by an result card components
So, to sum up, the server passes the search results to the search page.
Then I iterate the results and then return a number of result cards.
In the result card, it allows users to make an action like raise like.
The reason I can keep it dynamic without calling the API is I kept these two hook.
const [likeCount, setLikeCount] = useState(movie.likeBy.length);
const [liked, setLiked] = useState(false);
But the problem is that when the user clicks the "sort by like", even it gets the new sorted search result. The result card component is still keeping previous data values. It makes the new render weird. That's why I want to make a complete reload that can clear all components' states.
And I found that router.push doesnt do the job
Hope this explains things clear
why do you need to reload the page to get new data you can do it in the same URL
let's assume your baseurl ===>>> "getmovies?sortby="
if you don't pass the value in sortby then it will fetch all data
after adding value in sortby query it will fetch sorted data
sorturl ===>>>"getmovies?sortby=like"
You can use optimistic UI (which is persistence), I have used it with GraphQL and Facebook uses something similar. As soon as a user likes a movie, React updates the cache which it uses to render the UI. It makes the API call in the background and if it is successful, the UI remains the same (hence optimistic).
Edit:
After you have updated your question, I think we can look into states. Currently you are updating states when user likes a movie but when they sort it again, we are using the old results object or array returned from the server at the first time. If we are not calling the server everytime a user sorts the results, we can store a result copy in a component state fetched from the API and consider it as a source of data for dynamic rendering. Now if a user likes a movie, you update the local state of the result object, it will cause render and updates the UI. When user try to sort the movies, you use local state which has all the latest information and sort it.
I'm using Google Photos API to access albums.
Users can have in an album anything from a single photo to thousands of photos.
Is there a way to get something like an ETag to know if an album has changed since a previous known state?
Currently, the only way I could find is to iterate over all the images, and having to do that in 100 photos each time can take a lot of calls just to find out at the end that nothing has changed.
You want to know whether the album of Google Photos has been changed.
I could understand like above. Unfortunately, in the current stage, there are no metadata like the modified date when the contents in the album were changed. So in my case, I use the following workaround. Please think of this as just one of several workarounds.
Workaround:
If the number of photos in the album is changed, it can be known by the property of mediaItemsCount.
If the cover photo is changed, it can be known by the property of coverPhotoBaseUrl.
If several photos in a album are changed without increasing and decreasing the number of photos, unfortunately, in the current stage, I think that it is required to confirm the creationTime, filename and so on using the method of mediaItems.list.
By confirming from above in order, I can know about the change of the album.
References:
Method: albums.list
Method: albums.get
Method: mediaItems.list
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.
Is there any way to get the track index in an album? or given a track URI, is it possible to know its index or offset in the album (assume the track belongs to an album) without walking through the whole album?
Thanks.
Yes he is referring to sp_track_index, wich is only accessible through a album browse.
see libspotify documentation for sp_track_index here
What you need to do is something along the lines of:
call sp_albumbrowse_create for the album of sp_track that you have
wait for the callback fired when created/loaded
get sp_track_index from that track. Preferably you put the specific track in userdata to be passed on to the callback to be used with comparison.
Note: getting sp_track_index outside of an browse, will always return 0.
See Browse example here
You have to do an album browse for the target album. Once you've done that, you can get the track's index.
In Amazon Mechanical Turk, when creating an External Question then it will send you each assignment like this:
http://tictactoe.amazon.com/gamesurvey.cgi?gameid=01523
&hitId=123RVWYBAZW00EXAMPLE
&assignmentId=123RVWYBAZW00EXAMPLE456RVWYBAZW00EXAMPLE
Surprisingly, it doesn't send me the workerId and I can't find any way to do this. The closest method is GetAssignmentsForHIT which only gives me the assignment already submitted but I need to render the assignment based on the worker history.
As msha points out, the sending of a workerID parameter to an ExternalQuestion page seems to be deprecated, or at least taken out of the latest version of the documentation.
However, a fellow researcher who's been using MTurk a lot says: "People seem to be using it in the forums. I would go ahead with it...if it ever actually disappears, I'm sure that the developer community will yell very loudly. :) "
I tried it empirically today (2011-08-19), and indeed a workerID is being sent to the ExternalQuestion page I set up on my own server, after the HIT has been accepted. This was in the sandbox. My ExternalQuestion page contained a Java Web Start button (as described here: http://download.oracle.com/javase/tutorial/deployment/deploymentInDepth/createWebStartLaunchButtonFunction.html ); I don't know if that made any difference.
A recent addition to the API is the GetAssignment call, which takes the assignment ID as an argument and will return the Worker ID inside the Assignment data structure.
According to the MTurk docs here,
When a Worker accepts your HIT, you can get the ID of the Worker. If
your HIT contains a Java Applet, an IFrame, or embedded binary data,
the URL contains a value for the workerId. If your HIT does not
contain these types of data, or if a Worker has not accepted the HIT,
the workerId element doesn't appear.
Haven't tried to confirm this myself yet.