How to get total number of tracks in a playlist using soundcloud json API - soundcloud

I am trying to paginate the track list of a set/playlist obtained via soundcloud JSON API. Pagination technique described here works fine if I want to generate tracklist of x number of tracks for next page only. What I am trying to do is to make a numbered pagination with multiple page links. I didn't find any parameter such as "track_count" which returns the total number of tracks for "/user/tracks". So, can anyone give me any insights on making a numbered pagination for a playlist when getting data via soundcloud JSON API? thanks

/users endpoint has "track_count" property in the returned representation of user:
$ curl "http://api.soundcloud.com/users/3207.json?client_id=YOUR_CLIENT_ID"
{
"id": 3207,
"permalink": "jwagener",
"username": "Johannes Wagener",
"uri": "http://api.soundcloud.com/users/3207",
"permalink_url": "http://soundcloud.com/jwagener",
"avatar_url": "http://i1.sndcdn.com/avatars-000001552142-pbw8yd-large.jpg?142a848",
"country": "Germany",
"full_name": "Johannes Wagener",
"city": "Berlin",
"description": "<b>Hacker at SoundCloud</b>\r\n\r\nSome of my recent Hacks:\r\n\r\nsoundiverse.com \r\nbrowse recordings with the FiRe app by artwork\r\n\r\ntopbillin.com \r\nfind people to follow on SoundCloud\r\n\r\nchatter.fm \r\nget your account hooked up with a voicebox\r\n\r\nrecbutton.com \r\nrecord straight to your soundcloud account",
"discogs_name": null,
"myspace_name": null,
"website": "http://johannes.wagener.cc",
"website_title": "johannes.wagener.cc",
"online": true,
"track_count": 12,
"playlist_count": 1,
"followers_count": 417,
"followings_count": 174,
"public_favorites_count": 26
}

This question is already old, but I hope this could help other people.
You could use either of this endpoint:
http://api.soundcloud.com/playlists/{playlist_id}?client_id={client_id}
https://api.soundcloud.com/playlists/{playlist_id}?oauth_token={oauth_token}
The 2nd API is undocumented, the first endpoint suddenly started to return 401 for no reason which is from the SoundCloud API documentation. I still provided the 1st endpoint as it's only not working at work, but behaves correctly at home IP address. I suggest if you'd use the 2nd API to generate and use a non-expiring token.
SoundCloud is not a reliable provider anymore as there's no app support for developers. You just have to figure things out by yourself.
On the JSON response, look for track_count. That'll give you the number of tracks in a playlist.

Related

How to get "daily" video views Facebook API?

I have a little experience dealing with Facebook Graph API. I need to get daily views for the video as oppose to lifetime views.
FB API docs don't show this to be an option (lifetime - only period param)
https://developers.facebook.com/docs/graph-api/reference/video/video_insights/
However, I've seen another post on SO answering this question, yet for some reasons it doesn't work for me
(Getting a video views with Facebook API).
This is my successful API call which returns lifetime stats as expected:
/{video_id}/video_insights/total_video_views/lifetime
This is what I thought I should be doing:
/{video_id}/video_insights/total_video_views/day
... but got this error:
{
"error": {
"message": "(#100) Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": "Daily query is not supported for metric (total_video_views)"
}
}
Then, as the SO post suggested, I tried different period param:
/{video_id}/video_insights/total_video_views/month
... and got this:
{
"error": {
"message": "(#100) Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": "Period should be either lifetime or day."
}
}
... which tells that day should be acceptable param just like lifetime
Eventually, just for fun, I thought I'll pass "wrong" param - Day:
/{video_id}/video_insights/total_video_views/Day
... and got this:
{
"error": {
"message": "(#100) For field 'video_insights': period must be one of the following values: day, week, days_28, month, lifetime",
"type": "OAuthException",
"code": 100
}
}
This states that all of these values are good (day, week, days_28, month, lifetime), yet they don't work.
I'm really confused here. I saw daily break down for a video views on FB webpage/insights and thought it should be possible to do the same through the API.
What am i doing wrong?
I encountered the same problem shortly after your post. All of my testing and research has led me to believe Facebook has removed the ability to retrieve anything other than lifetime. After reading all of the Change Log for the last few releases, I don't see any evidence of this change being documented by Facebook. This is obviously very disappointing.
The API responses clearly indicate "day" should be a valid period, which leads me to believe it was hastily removed.
Unfortunately I do not see a reliable workaround. One may be able to achieve an approximation of daily by retrieving lifetime every 24 hours and calculating the difference between the two. This would only be an approximation though since there could be data reconciliation issues for a given time period.
It is too bad this issue didn't get any traction because it is core to the Facebook Video Insights API.
Here is my solution (after running this through FB support)
basically,
1) i get list of all posts:
fields='object_id,type'
url="https://graph.facebook.com/v3.2/{}?access_token={}&fields={}&limit={}".format(resource_id,access_token,fields,limit)
while url:
rec=requests.request(method="GET",url=url)
content = json.loads(rec.content)
if "next" in content["paging"]:
url=content["paging"]["next"]
else:
url=False
break
2) then, i iterate through each of them (filtering those with videos) and retrieve data for the post which contains this video rather than video itself (which turned out to be not possible anymore with daily grouping)
insights=[]
video_post_id=page_id+"_"+video_id
metric="post_video_views"
url_insight=f"https://graph.facebook.com/v3.2/{video_post_id}/insights?metric={metric}&since={since}&until={until}&pretty=0&access_token={access_token}"
while url_insight:
rec=requests.request(method="GET",url=url_insight)
insight = json.loads(rec.content)
if "next" in insight["paging"]:
url_insight=insight["paging"]["next"]
else:
url_insight=False
break
this worked for me

Get Facebook share/like/comment count of URL

Prior to today, I used the following URL to get the Facebook share/like/comment count of a URL:
https://api.facebook.com/method/links.getStats?format=json&urls=http://stackoverflow.com/
Today, Facebook removed this feature. So now I'm using this:
https://graph.facebook.com/v2.7?emc=rss&fields=og_object{engagement},share&access_token=<ACCESS_TOKEN_GOES_HERE>&id=http://stackoverflow.com/
Which outputs:
{
"og_object": {
"engagement": {
"count": 45267,
"social_sentence": "45K people like this."
},
"id": "10150180465825637"
},
"share": {
"comment_count": 12,
"share_count": 45267
},
"id": "http://stackoverflow.com/"
}
The problem is, share_count is the total of likes + comments + shares (as far as I know).
Is there a way to get the number of likes, comments, and shares separately?
Looks like a bug in fb-api.
My solution:
receive the number of shares/comments as you describe in your question with
graph.facebook.com/?fields=og_object{id},share&id=https://stackoverflow.com/
save shares/comments count
save fb object-id of url
og_object->id
get likes count with (max limit is 1000, then you can use paging):
graph.facebook.com/OBJECT_ID/likes?access_token=ACCESS_TOKEN&pretty=1&limit=1000
UPD 2016-08-22
I found a solution that allows you to get the number of likes/reposts/comments in one step:
https://graph.facebook.com/?fields=og_object{likes.limit(0).summary(true)},share&ids=http://google.com,http://twitter.com
It is not currently possible.
Facebook is adding likes/shares/comments for URLs and returning them as shared_count.
Not possible to return correct number of individual likes/shares/comments, and that is not clear in the Graph API documentation. Not clear if it is a bug or a documentation error.
The old Rest API that provided this data was turned off on the 18th August.
There is a comment from a Facebook engineer explaining this in reply to a bug report, in the answer to this Stack Overflow question:
Getting Facebook Share, Like and Comment Counts for a Given URL with API Graph v2.6
You can also subscribe to this bug report at Facebook, but is a bit old with still no solution:
https://developers.facebook.com/bugs/748651458568287/

Get Reactions using the Github api

Github issues may contain "reactions" for quite a while (as described here: https://github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments)
I would like to receive that information using the Github api, but there doesn't seem to be anything like that when getting an issue e.g.
api.github.com/repos/twbs/bootstrap/issues/19575
that information does not seem to be inside that response. Also, I did not find another API call that could retrieve that information. How to get those "reactions"?
This is now possible, being the preview state (meaning, you have to pass a custom Accept header in the request). Check out the GitHub API documentation page
Example
$ curl -H 'Accept: application/vnd.github.squirrel-girl-preview' https://api.github.com/repos/twbs/bootstrap/issues/19575/reactions
[
{
"id": 257024,
"user_id": 947110,
"content": "+1"
},
...
{
"id": 888868,
"user_id": 1889800,
"content": "+1"
}
]
The endpoint looks like this:
GET /repos/:owner/:repo/issues/:number/reactions
You can even pass a content parameter (querystring) indicating what kind of reaction you want to retrieve.

Facebook API not working sometime for some URL

I'm getting number of shares and comment of blog posts using facebook graph api for my blog, but sometimes it do not return shares and comment.
Following URL is not giving number of share and comments.
http://graph.facebook.com/?id=http://www.lehedonist.com/jeans-is-the-new-whiskey-2001
BUT it is working for this URL:
Example: http://graph.facebook.com/?id=http://www.lehedonist.com/spring-slam-fashion-war-ss16-1965
I somehow wonder why it's even working to request these URLs without an access token to be honest.
See
https://developers.facebook.com/docs/graph-api/reference/v2.5/url
It only gives a result if there no version info in the URL. To do this in the v2.5 way properly, you'd have to use
https://graph.facebook.com/v2.5/?access_token={access_token}&fields=id,og_object,share&id=http://www.lehedonist.com/spring-slam-fashion-war-ss16-1965
where {access_token} is an actual access token.
Results will look like
{
"id": "http://www.lehedonist.com/spring-slam-fashion-war-ss16-1965",
"og_object": {
"id": "987675524635070",
"description": "Not your usual fashion post, we decode styles best suited to your personality and what should you be sporting next summer",
"title": "Spring Summer 16 fashion: The clash of fashion personalities",
"type": "article",
"updated_time": "2015-10-08T11:24:32+0000",
"url": "http://www.lehedonist.com/spring-slam-fashion-war-ss16-1965"
},
"share": {
"comment_count": 2,
"share_count": 81
}
}

How to get the right Data to an external URL and the right ID through the API?

is there a possibility to get more informations to a specific url e.g. preview image, title and short description through the open graph? If you do something like this, you only get the "shares" //graph.facebook.com/http://www.google.de
It's a bit confusing, when I get the ID via FQL through the object_url Table I get a different ID to the ID I get from the Debugger.
Getting the ID:
//graph.facebook.com/fql?q=SELECT%20url,id,type,site%20FROM%20object_url%20WHERE%20url%20=%20%22http://google.de%22
Result: "id": 6319338796</pre>
Trying to get the Data with that ID failed (acces token needed)
//graph.facebook.com/6319338796/
"message": "An access token is required to request this resource."
Get the ID with the Debugger:
//developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fgoogle.de
Getting the Result from ID 438699604740 (no problem):
//graph.facebook.com/438699604740
{
"url": "http://www.google.de/",
"type": "website",
"title": "Google",
"image": [{"url": "http://www.google.de/images/google_favicon_128.png"}
],
"updated_time": "2012-12-19T15:26:32+0000",
"id": "438699604740"
}
I am just wondering, why there are two different object IDs for the same URL and why do I need for the one an acces_token and not for the other?
The question is, how to get the right Data and the right ID throug the API? Or are there any restrictions to get these Data from a URL?
Thanks for help!