How to get last week top tracks of an artist using last.fm API? - api

I want to fetch the last week top tracks of an artist using the last.fm API but I don't see any relevant method call for that.
I looked at artist.getTopTracks method but it returns the overall top tracks of an artist.
So, is there any way I can fetch just the last week top tracks using the API.

Unfortunately no way to get this info via their API. Bit strange indeed as the last week top tracks chart is listed default on an artist page at the last.fm website. So you have to use some good old web scraping techniques.

Related

Use Youtube API to get a top channels for each category

I'm currently trying to build a simple app that lists the top n channels for each category using the YouTube API. The problem I'm currently facing is that I don't know what query would give me the top channels for a given category.
I've already tried using the guideCategories resource to get every channel category. A basic query would give me every category. I would then use the name of each category and use the Search resource (setting q to the name of the category) to get what I think is a list of the top channels. I think I'm doing it wrong though because I've seen several resources like SocialBlade that show a completely different list of channels.
Does anyone have any idea on how I could get closer to the end goal of getting top channels for a specific category?
I don't see any documentation about getting the top channels for specific category. You can only get the top videos within a channel. I've also seen this related SO post which discussed on how to retrieve a list of the most-viewed channels by region.

Youtube API v3 Playlistitems returns different order than on youtube.com

I'm creating a script that grabs the newest videos from the uploaded videos from a channel. It remembers which video it processed last and if it comes across that same videoId it quits. This works beautifully, until I cam across a playlist that does not have the newest added video at position 1 in its uploaded playlist.
The strangest thing however, is that on youtube.com the same playlist does have the correct order:
https://www.youtube.com/watch?v=x_HvPmd9L9o&list=UUpsSadsgX_Qk9i6i_bJoUwQ
But in the Youtube API response the order is different:
https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+contentDetails&maxResults=50&playlistId={YOUR API KEY}&key=AIzaSyBtO0Bl38DJKCuPh9e4mRW3-1UcGPPnQfs
Is it something that i'm doing wrong with my API call or is this a bug in youtube? I can't find an option to sort playlistitems by date or anything.
Which got me thinking, when users create playlist they are usually ordered from oldest added -> newest added. Do you have to call all pages just to get the newest added? That seems to be madness.
The YouTube API for retrieving the playlist from a channel does not provide any parameter where we can set the order in which we want to retrieve the playlist. We do not have how the internal algorithm for fetching the video data works. But from your analysis it seems that the UI API on the live site is different from the data retrieved from the API's.
Although the yt:position tag specifies the order in which a video appears in a playlist.
Example
<yt:position>4</yt:position>
As far as I can see it lists them in upload order.
Let's assume you are batch uploading episodes 1-5 of a series.
You select the five videos and drag into the upload window. YT will upload them in the order it was given by your OS (often #1, #5, then #'s 4, 3 & 2).
You can set the videos to publish on successive days: #1 on Monday, #2 on Tuesday etc. which will show in the correct order on your channel page.
The API call will only bring back published videos so if you make the call on Weds after #3 is published, you will get 3 videos in your response [probably] ordered #1, #3 & #2.

how to display Google Plus average rating on my website?

I want to put Google+ badge of a business on my page. I can get code for it using Google Developer website: https://developers.google.com/+/web/badge/#badge
But i do not understand how to get average score and number of reviews so I can feature them on my website as well - something similar to what you get when you search for a place:
for example, here is a restaurant's Google+ page: https://plus.google.com/106659611775440325701/about?hl=en - it clearly displays all those reviews and scores. How to get this information from Google? Is there a way to modify badge's code to include them?
Reviews data is part of the Places API. There are a couple of options for getting them on your site.
The Maps Embed API would be the easiest but requires loading a map on your page.
Using the Maps JS API v3 you can load and render place details client side.
Using the HTTP API you can load details on your server to cache in a DB and render on page load.
UPDATE May 2019: it is possible now to get total number of reviews using Place Details Place APIs call: https://developers.google.com/places/web-service/details#fields
as of Jan 2019, it returns user_ratings_total field: https://developers.google.com/maps/documentation/javascript/releases#335
so looking at this again 3 years later, we still can't get all reviews for a place. We can get some - top 5 - using Place Details API call: https://developers.google.com/places/web-service/details
then there is a change request for Google team to extend this: https://issuetracker.google.com/issues/35825957
And finally, you can apply for Google Business Account and request access to extended API which allows you to get all reviews for a verified location: accounts.locations.reviews.list

Youtube data API version 3 pagination

I understand that youtube response contains the next and previous page tokens and we can use those to go to previous and next pages.
eg :
https://www.googleapis.com/youtube/v3/search?&key={key}&part=snippet&maxResults=20&order=viewCount&q=abc&type=video&videoDuration=long&videoType=movie&pageToken=Cd323A
My question is how can I navigate to nth page of particular search?
Please note that some people may see this is impossible. But I have seen some site implemented this.
Youtube API only provides NextPageToken and PreviousPageToken, that's it, sorry: see documentation here: https://developers.google.com/youtube/v3/docs/videos/list
You can still make a pagination item but you will have to implement it by calling multiple times the URL, passing the NextPageToken as pageToken in your requestion every time, and caching results.
By the way, this question is already answered here (see the 1st point of the answer): youtube data api v3 php search pagination?
Quoting them:
In particular your case where you need 50 pages per page and you are
showing 3 pagination like (1,2,NEXT) then you need to fetch results
two times. Both the results you will keep in cache so for page 1 and 2
results will be retrieved from cache. For next you make it sure that
you are making query google again by sending nextPageToken.
Thus to show pagination 1-n and every page 50 results then you need to
make n-1 queries to google api. But if you are showing 10 results per
page then you cane make single query of 50 results using which you can
show first 5 pages (1-5) with the help of retrieved results and at
next you should again send next page token like above.
NOTE- Google youtube api provide 50 results max.
nextPageToken and prevPageToken comes with the api request.
Now you save the token in an array and then insert it as a nextPageToken in another api call and you will get the next page. The same way you will get a prevPageToken when u get the next page results.
Hope it helps.

Get A Users Over All Retweet and Mention Counts using Twitter API

We are working on some analytics using the amount a user is retweeted or mentioned... I can't seem to find a way to get these numbers using the apis does anyone have any ideas?
https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name={screen_name}&count={count}
it's important to include the line include_entities=true to the request. This will give you an expanded response including re-tweet and mention counts.
Get Status / User Timeline
Twitter API Console
Update:
to get tweets from the last 90 days, there is a Node.js library you can use called Snapbird
https://github.com/remy/snapbird
.. and here is another resource covering the same topic.
http://blog.tweetsmarter.com/twitter-search/10-ways-and-20-features-for-searching-old-tweets/