Why does this SoundCloud API method not retrieve all tracks? - soundcloud

I'm attempting to retrieve all of my favourited songs from my profile on SoundCloud using the SoundCloud API method /users/{id}/favorites.
After registering my application with SoundCloud and retrieving my ClientID, I can successfully retrieve an array of favourited tracks in JSON using a call to http://api.soundcloud.com/users/goodforenergy/favorites?client_id={my-client-id}.
Looking at my SoundCloud profile, however, you can see I have (at this moment in time) 182 likes - but the method is only returning 48.
Any ideas as to why? I thought there may be a next_href returned in the JSON that I was expected to follow to retrieve more, but I don't see any. In any case, 48 seems a very arbitrary number to return!

According to soundcloud api docs most of the results in the API are returned in collections which are limited by default to a size of 50. I realize that it's peculiar that you are seeing 48 rather than 50 but it's probably worth modifying your call to support pagination.
Most endpoints support a linked_partitioning parameter that will allow you to page through collections. When this parameter is passed, the response will contain a next_href property if there are additional results.
So you need to update your API call to include the linked_partitioning and limit parameters in order to recieve a next_href.

Related

How to get live video id from YouTube channel

YouTube API eventType=live not working, does anyone have an idea why?
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCmyKnNRH0wH-r8I-ceP-dsg&eventType=live&type=video&key=
Without eventType was working fine (but not now):
https://www.youtube.com/embed/live_stream?channel=UCmyKnNRH0wH-r8I-ceP-dsg&autoplay=1
Looks like YouTube changed something in API, search.list really not returning live broadcast since end of last week.
If you have user's access token you can use https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&broadcastStatus=active&broadcastType=all
endpoint to retrieve if any broadcast is live.
If you do not have user's access token, you can try this answer
but i didn't check it if it is working
Anyway this question looks like to be a duplicate of this question
Right now the YouTube API is not working, specifically for retrieving live streams of a specific channelId. In other words if you are setting channelId in the API call, you will get 0 results.
If you're using an API key rather than OAuth (not sure if OAuth works) the only work around at the moment is to use the API to search for a specific title. Here is my query URL below.
https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&type=video&maxResults=20&order=date&q=My+Uniquely+Titled+Livestream&key=[apiKey]
The results returned by the API will be from all of YouTube. (Note: the rest is done serverside) Put the results into an array and discard any that don't match your channelId. Then check the titles in an array and only get the video ID of the one that matches your desired title. That is the basic logic and it is sort of a rigid work around that won't work for most. But at least it will get you what you need until Google fixes the API.

How can I query multiple object insights in one Facebook API Call?

I saw this question (Query multiple insights metrics in one API call) but their answers are from 2012 and no longer work.
I want to get post_video_avg_time_watched and post_video_views in a single api call to Facebook.
How is this possible?
I don't want to use Facebook's batch request, because it counts against my rate limits twice instead of once.
Yes, and easily! Just add the second value after a comma and the first value like so: /insights/post_video_views,post_video_avg_time_watched/lifetime

Facebook API Post Impressions Unique (reach)

I'm after the impression uniques for our posts and ideally we would like one server call and it would bring back the last 100 posts with the reach (post_impressions_unique).
To get reach, I can currently do this using:
https://graph.facebook.com/nmemagazine/posts?fields=name,message,full_picture,created_time,shares,likes.limit(1).summary(true),comments.limit(1).summary(true)&access_token=USER_TOKEN
and getting the post ID, then calling: https://graph.facebook.com/v2.5/POST_ID/insights/post_impressions_unique?access_token=USER_TOKEN
Is there a way where I can make one call to get all recent posts and their reach in one API call?
You could simply call
https://graph.facebook.com/nmemagazine/posts?fields=name,message,full_picture,created_time,shares,likes.limit(1).summary(true),comments.limit(1).summary(true),insights&access_token=USER_TOKEN
NOTE: extra field "insights".
However, as far as I can tell you cannot limit the insights to just Post_impressions_Unique so it would bring back some data you do not necessarily want/need. I.e. I don't think you can perform a search/filter on a "second level"/child/nested type.
To give an update on this:
In facebook Graph API 2.10, you can (and have to) specify the metrics you are interested in via insights.metric(...). Possible metrics are documented here:
https://developers.facebook.com/docs/graph-api/reference/v2.10/insights#availmetrics
For your example:
curl -i -X GET "https://graph.facebook.com/nmemagazine/posts?fields=name,message,full_picture,created_time,shares,likes.limit(1).summary(true),comments.limit(1).summary(true),insights.metric(post_impressions_unique)&access_token=USER_TOKEN"

In Facebook Graph API - Is LIMIT parameter realy functional?

I'm trying to collect all the posts of my company page with this kind of query
https://graph.facebook.com/v2.2//feed?limit=250&fields=id,type,status_type,comments{id},likes{id},shares
Problem is that I'm not collecting all posts.
I will have a better result with limit=20 and some time with limit=100
Most of the pages (from the pagination mechanism point of view) will not have 100 items.
I know some posts may not be exposed because of privacy settings.
My issue is that a call with limit=20 is not returning once going through pagination the same amount of data as limit=250.
How could it be?
How providers of Facebook Analytics can garanty the quality of data they collect ?
The Facebook graph api only allow the max of 100 items per request, despite you specify more than that.
Afaik the limit parameter is indeed buggy. But 250 would be a very high value, there is a max value for the parameter too - i assume it depends on the API call how high it is, could be fixed too.
Better donĀ“t use limit at all and use paging to get more results: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging

Order by playbacks when fetching tracks from SoundCloud

I am fetching a list of tracks from soundcloud's API using the following query to retrieve the 5 most popular tracks:
https://api.soundcloud.com/tracks?client_id=XXX&order=hotness&limit=5
But recently SoundCloud removed the hotness order. In the blog post they say tracks can instead be sorted by playback_count. But can this be done in the query or do they suggest I pull down the whole SoundCloud library and order them in the client? The following doesn't seem to work:
https://api.soundcloud.com/tracks?client_id=XXX&order=playback_count&limit=5
So how would one retrieve the top tracks on SoundCloud?
The solution was to use the undocumented calls for the explorer feature that SoundCloud itself uses (I used the dev tools in Chrome to check the AJAX calls).
https://api.soundcloud.com/explore/sounds/category?limit=L&client_id=XXX
This appears to use some sort of sorting on the popularity of the songs. The songs can then be filtered on only music by checking the "grouping" attribute. I then have to resolve the list of IDs to actual songs which can be done with the (documented, official) API call:
https://api.soundcloud.com/tracks?ids=1,2,3&client_id=XXX
This seems to work perfectly and I also get the added benefit of an even distribution among genres. But of course, this can stop working at any moment since the API calls are undocumented and perhaps not meant for public use.
Just wanted to provide an update. It seems soundcloud has moved to v2 of the explore API call.
Use this to get a list of categories:
https://api.soundcloud.com/explore/v2
And this to get tracks from a category:
https://api-v2.soundcloud.com/explore/metal?limit=10&offset=0
So far it seems to without a key, although I have no idea how long that will last.
EDIT: So the 2nd url doesn't seem to allow cross-origin, but so far this does work, though it only returns the trackID not the full information
https://api.soundcloud.com/explore/v2/metal?limit=50&consumer_key=XXX
check here, soundcloud removed order by hotness.
Has order by hotness been removed from Soundclouds API
so, for now, only order by date is possible.