Access Soundcloud Charts with API - soundcloud

Is there an way to access the new charts https://soundcloud.com/charts/top (top 50) with the soundcloud api? Or is there an other way?
Maybe with an crawl with php or something?

To found parameters that you can use with HTTP API Request, you can do this:
Go to "https://soundcloud.com/charts/" and open Console (F12 on Chrome).
Go inside Network Tab of Console and Refresh page (F5).
Clear Console.
Now for example if you want know parameters for retrive "TOP 50 - Dance & EDM":
Change values inside the filter box
Check in the console, the request that start with: "charts?kind="
Search inside this url the parameters.
Some example:
TOP | Dance & EDM
https ://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Ageneres%3Adanceedm&client_id=...
TOP | Deep House
https ://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Agenres%3Adeephouse&client_id=...
New & Hot
Country
https ://api-v2.soundcloud.com/charts?kind=trending&genre=soundcloud%3Agenres%3Acountry&client_id=...
All Parameters:
kind:
top <- Top 50
trending <- New & Hot
genre:
soundcloud:genres:all-music
soundcloud:genres:all-audio
soundcloud:genres:alternativerock
soundcloud:genres:ambient
soundcloud:genres:classical
soundcloud:genres:country
soundcloud:genres:danceedm
soundcloud:genres:dancehall
soundcloud:genres:deephouse
soundcloud:genres:disco
soundcloud:genres:drumbass
soundcloud:genres:dubstep
soundcloud:genres:electronic
soundcloud:genres:folksingersongwriter
soundcloud:genres:hiphoprap
soundcloud:genres:house
soundcloud:genres:indie
soundcloud:genres:jazzblues
soundcloud:genres:latin
soundcloud:genres:metal
soundcloud:genres:piano
soundcloud:genres:pop
soundcloud:genres:rbsoul
soundcloud:genres:reggae
soundcloud:genres:reggaeton
soundcloud:genres:rock
soundcloud:genres:soundtrack
soundcloud:genres:techno
soundcloud:genres:trance
soundcloud:genres:trap
soundcloud:genres:triphop
soundcloud:genres:world
soundcloud:genres:audiobooks
soundcloud:genres:business
soundcloud:genres:comedy
soundcloud:genres:entertainment
soundcloud:genres:learning
soundcloud:genres:newspolitics
soundcloud:genres:religionspirituality
soundcloud:genres:science
soundcloud:genres:sports
soundcloud:genres:storytelling
soundcloud:genres:technology
Example in php to get a json response of TOP50 - Country:
URL:
https ://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Agenres%3Acountry&client_id=XXXXXXXXXXX&limit=10&linked_partitioning=1
URL Parameters:
Kind: Top
Genre: soundcloud:genres:country
client_id: XXXXXXXXXXX
limit: 10
linked_partitioning: 1
limit: how many songs you want to receive in response.
linked_partitioning: page number, according to the limit.
e.g. linked_partitioning with Limit = 10:
1 get song from 0 to 9
2 get song from 10 to 19
...
e.g. linked_partitioning with Limit = 20:
1 get song from 0 to 19
2 get song from 20 to 39
...
Now that you have URL, if you want retrive JSON response with PHP
you have to write for example:
<?php
$url = "https://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Agenres%3Acountry&client_id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&limit=10&linked_partitioning=1";
// Get JSON Response
$json = file_get_contents($url);
// Decode response to array
$objectJSON = json_decode($json, true);
Example Json Response:
{
"genre":"soundcloud:genres:country",
"kind":"top",
"last_updated":"2016-03-24T09:50:02Z",
"collection":[
{
"track":{
"commentable":true,
"comment_count":211,
"downloadable":true,
"download_count":80,
"duration":251060,
.
.
.
"kind":"track",
.
.
.
.
"license":"all-rights-reserved",
"streamable":true,
"title":"Award winning Falling Star",
"uri":"https://api.soundcloud.com/tracks/245170733",
.
.
.
"country_code":"US"
}
"score":1093171.0
},
{
...
},
OTHER TRACKS HERE...
],
"query_urn":"soundcloud:charts:bc9b903f2cee44e7bca955bc2fc4601d",
"next_href":"https://api-v2.soundcloud.com/charts?genre=soundcloud%3Agenres%3Acountry&query_urn=soundcloud%3Acharts%3Abc9b903f2cee44e7bca955bc2fc4601d&offset=20&kind=top&limit=20"
}
}
If you want read JSON content of response:
// Read Json taking for example Name, Title and SoundCloud URI of song.
foreach ($objectJSON["collection"] as $key => $value) {
echo 'user: ' . $value['track']['user']['full_name'] . "<br/>";
echo 'title: ' . $value['track']['title'] . "<br/>";
echo 'url: ' . $value['track']['uri'] . "<br/><br/>";
}
echo $response;
?>
Result of this PHP:
user: ...
title: ...
url: ...
user: ...
title: ...
url: ...
...
Example of this code
I hope I have helped you and sorry for my english.
EDIT:
I think that SoundCloud has changed the way to get the next page.
Now you need to change the "offset" param.
Like this:
Page 1: ....&limit=20&offset=0
Page 2: ....&limit=20&offset=20
Page 3: ....&limit=20&offset=40
ANSWER FOR #VietHung QUESTION.
Q: Can you explore system playlists?
(Eg: soundcloud:system-playlists charts-top:all-music)
To find system playlist, I have used Charles Web Debugging Proxy.
The idea is to sniff network package sent by SoundClound App from iOS device (in my case).
After that you configure Charles to sniff SSL packages correctly, you can use you pc as proxy for your smartphone.
(You must install Charles cert on Windows and on iOS device to sniff SSL packages correctly, for more information search on google).
Now, open SoundCloud App and click on every playlists (TOP, NEWS) inside the app.
Below a screenshot (Quality powered by paint, sorry ahah):
Now inside Charles we can see something like this:
I set the focus only on the SoundCloud host for better reading of incoming packages.
Charles is smart and puts all similar requests into a subfolder, in our case we have to look at all the requests within 'system-playlist'.
Now from all requests you can retrieve all system playlists values.
I have not listed all playlist song because currently I do not have much time.
As soon as I can, I edit this post with the complete list of possible system playlists vales.

Here is an example:
https://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Agenres%3Aall-music&client_id=02gUJC0hH2ct1EGOcYXQIzRFU91c72Ea&limit=20&offset=0
Just change the params according to your client id, etc.

Related

Whats the sharepoint rest endpoint to get a web by its id

I have a webid and a listid in a sharepoint page. I'm trying to construct a rest url to get to the list.
I cant figure out the url to get the web given the WebID.
I tried
https://xxxx.sharepoint.com/_api/web/webs(guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d')
https://xxxx.sharepoint.com/_api/web/webs('33213c5c-30e5-468c-87f7-52b48a7b6a3d')
https://xxxx.sharepoint.com/_api/web/webs/GetById('33213c5c-30e5-468c-87f7-52b48a7b6a3d')
How do I get at the web with that id? I need to get a list in the web.
I was thinking it was going to be as simple as
https://xxxx.sharepoint.com/_api/web/webs(guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d')/lists(guid'the-list-id'), but I cant get at the web!
++++++++++++++++ mReply to vadim ++++++++++++++++++++++++
Thanks Vadim,
You got me pointed in the right direction
This url will get me to the web:
https://xxx.sharepoint.com/_api/web/webs?$filter=iD eq guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d'
This url will get me all items in all lists in all webs
https://xxx.sharepoint.com/_api/web/webs?$expand=lists,lists/items
This url will get me all items in all lists in a specified web:
https://xxx.sharepoint.com/_api/web/webs?$expand=lists,lists/items&$filter=iD eq guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d'
But how doe I get all items in a specified list in a specified web?
This doesnt work:
https://xxx.sharepoint.com/_api/web/webs?$expand=lists,lists/items&$filter=((iD eq guid'33213c5c-30e5-468c-87f7-52b48a7b6a3d' ) and (Lists/Id eq guid'd38444af-dd7f-404b-9e75-b1f8c6cdee7d' ))
Its a valid Web id and a valid list id, but sharepoint complains :m:message xml:lang="en-US">Field or property "Id" does not exist.
any ideas?
Web resource could be retrieved using $filter query option as demonstrated below:
/_api/web/webs?$filter=ID eq guid'c01e1b4a-e671-431d-97aa-4b02a57803c7'
In order to retrieve the corresponding List resource by id you could consider the following approach:
Perform request to get Web Url by its Id:
/_api/web/webs?$select=ServerRelativeUrl&$filter=ID eq
guid'c01e1b4a-e671-431d-97aa-4b02a57803c7'
Get List by id: {web url}/_api/Web/Lists(guid'b778bbec-dd69-4a6c-9437-c73972c36292')
where {web url} is web site url found in the first request

Facebook page tab app session across subpages PHP SDK 4

See the full original question further down
Using the latest Facebook PHP SDK 4.4.0, in my main app page I can do the following to get a user id etc.
<?php
FacebookSession::setDefaultApplication(APP_ID, SECRET);
$helper = new FacebookRedirectLoginHelper( PAGE_URL );
$pageHelper = new FacebookPageTabHelper();
$session = $pageHelper->getSession();
echo '<p>You are currently viewing page: '. $pageHelper->getPageId() . '</p>';
// get user_id
echo '<p>User Id: ' . $pageHelper->getUserId() . '</p>';
// **depcrecated** get like status - use for likegates
echo '<p>You have '. ( $pageHelper->isLiked() ? 'LIKED' : 'NOT liked' ) . ' this page</p>';
// get admin status
echo '<p>You are '. ( $pageHelper->isAdmin() ? 'an ADMIN' : 'NOT an ADMIN' ) . '</p>';
?>
This does not work on sub pages of my app ... Why is the session (and amongst other things, the signed request) lost? How can I get them back and how can I get methods such as getUserId() from the the FacebookPageTabHelper to continue to work on sub pages?
full original question
I'm fairly new to Facebook app development and I'm having problems with session management and I just can't seem to be able to wrap my head around it. Of course it doesn't help that the official documentation is almost useless.
My problem is that the page session get lost when moving away from the apps main page to a subpage within the Facebook page tab app iframe.
I use the following PHP code to obtain the session and user id on the main (initial) app page and it works great:
<?php
FacebookSession::setDefaultApplication(APP_ID, SECRET);
$helper = new FacebookRedirectLoginHelper( PAGE_URL );
$pageHelper = new FacebookPageTabHelper();
$session = $pageHelper->getSession();
?>
But it doesn't work on sub pages :( when a user clicks on a menu item (or any other link inside the app/iframe), the session goes bye bye. Which is not ideal as I need the user id of the user to track whether or not that user has completed certain actions. Of course I could send the ID along with every request, but there must be a way to have a persisting session, no?
Is there a way to retrieve the session on a sub page in PHP? If so, how? Or do I have to load additional content using javascript? And how would that work, if I can't keep the session between requests and therefore have no way of identifying which user a request came from? How do others handle this?
What I'd like to avoid is to write my own user session management, which would solve the problem but is simply not in the budget and I was hoping I could work with what Facebook already had on offer. Especially since my app doesn't require user information/permissions of any kind.
Thanks a lot in advance for any info on this topic, greatly appreciated, going in circles here.
Edit to clarify: I thought of just saving the Facebook session in a PHP session cookie, but how would I use that to reconnect with Facebook after changing the page?
I finally managed to solve this problem. I'm not sure whether this is considered the right way or can even be a recommended way of doing this, but it works and since time is of the essence, I don't have much of a choice.
If anybody has any further ideas or suggestions, please comment.
Here's how I did it:
// store the signed request
if(isset($_REQUEST['signed_request'])) {
$_SESSION['signed_request'] = $_REQUEST['signed_request'];
} elseif($_SESSION['signed_request']) {
$_REQUEST['signed_request'] = $_GET['signed_request'] = $_POST['signed_request'] = $_SESSION['signed_request'];
}
// assign the stored signed request to REQUEST, GET and POST vars (the unsavory bit, imo)
$_REQUEST['signed_request'] = $_GET['signed_request'] = $_POST['signed_request'] = $_SESSION['signedRequest'];
FacebookSession::setDefaultApplication(APP_ID, APP_SECRET);
$accessToken = APP_ID . '|' . APP_SECRET;
$this->session = new FacebookSession($accessToken);
$pageHelper = new FacebookPageTabHelper();
$isAdmin = ($this->pageHelper->getPageData('admin')) ? $this->pageHelper->getPageData('admin') : 0;
// get pade id
echo '<p>You are currently viewing page: '. $pageHelper->getPageId() . '</p>';
// get user_id
echo '<p>User Id: ' . $pageHelper->getUserId() . '</p>';
// get admin status
echo '<p>You are '. ( $isAdmin ? 'an ADMIN' : 'NOT an ADMIN' ) . '</p>';

How to put link in submit-button, using Clojure

I've been working on a Clojure project for some time and was wondering how to navigate user from one page to another after clicking the submit-button.
Code goes like this:
(defn view-film-input []
(view-layout
[:body {:style "background-color: #F2FB78"}
[:h2 "Add new film"]
(form-to [:post "/addfilm" ]
(label "movname" "Film title: ")
(text-field :txtname) [:br]
(label "prname" "Producer name: ")
(text-field :txtprname) [:br]
(label "location" "File location: ")
(text-field :txtlocation)[:br]
(label "duration" "Duration(minutes): ")
(text-field :txtduration)[:br]
(submit-button "Save"))]))
Now, this works but I would like to navigate user to same "Add new film" page, or refresh the form after clicking "Save" button, instead it shows just a blank page.
This is the GET\POST part:
(GET "/addfilm" [] (view-film-input))
(POST "/addfilm" [txtname txtprname txtlocation txtduration]
(insert-flick txtname txtprname txtlocation txtduration 90) )
Thanks in advance!
You have two possibilities here.
Redirect the User
Using the Location header of a HTTP 302 (or 303) response you can specify a path the user's browser should display instead of the current one:
(POST "/addfilm" [...]
...
{:status 302
:headers {"Location" "/addfilm"}})
There are also two functions in ring.util.response that would generate the responses for you: redirect and redirect-after-post - with the latter being more applicable to your use case.
EDIT: This answer elaborates on why 303 would be the status code to send after POST, specifically:
If you use 302, you're risking that UA will re-send POST to the new URL instead of switching to GET.
Render the same Page again
Simpler and prompting less I/O, but imposing some duplication would be to render the same view again, i.e.:
(POST "/addfilm" [...]
...
(view-film-input))
This seems less maintainable to me but it is probably the shortest path to solving your problem.

Finding broken links with Selenium Remote Driver

I have a site with login and i want to test all links present in that site.
I tried with finding links and click on each to verify with Selenium Remote Driver. But one problem i have is coming back to previous URL and selecting next link. This testing should be recursive.
How can we do this with Selenium Remote Driver?
Following program i tried to check broken links
sub traverse {
my ($self) = #_;
my $links = find_links("//a");
foreach my $index (1..$#$links) {
my $url = $links->[$index]->get_attribute('href');
my $result = $links->[$index]->click();
if ($result) {
traverse();
} else {
print "url is broken $url\n";
}
}
}
I know it's possible to do in C# by checking the returned status code. So you don't actually click on the link, but you are retrieving the header of the response that link is going to give. In this header you can find the HTTP Status Code which you can check to see if the link is giving a valid response or not. Plus you're not leaving the current site!
In C#, a possible method to get the status code will look like this (The checking of the HTTP status code is not included):
private static HttpStatusCode GetStatusCode(string url)
{
var result = default(HttpStatusCode);
var request = WebRequest.Create(url);
request.Method = "HEAD";
HttpWebResponse response;
try {
response = request.GetResponse() as HttpWebResponse;
} catch (WebException) {
return HttpStatusCode.NotFound;
}
if (response != null)
{
result = response.StatusCode;
response.Close();
response.Dispose();
}
return result;
}
Altough this is no Perl code, I hope this helps
Why are you not trying to use some tool, because your site can has over 9000+ urls, it's a lot of time and job, you can use Xenu
Install
In option check use Cookie
Run IE and login thorugh it
Run Xenu
P.S. To test privete part of your site, you must login thorugh IE because Xenu uses only IE cookie
Hmm, I've crossed this bridge before and here is how I solved it. Now I should say that I crossed this bridge before WebDriver :) so this is using WWW::Selenium instead of S:R:D but the concept is the same and still applies.
One of the most tedious tasks, IMO, for a test engineer, is manually verifying links. We can automate most of the process and as long as we have the URL's for where we are expected to land after clicking the link, we can verify this functionality using Selenium and a little bit of JS.
In the below example we first navigate to our desired website and then use Selenium's getEval() function to execute JavaScript that gathers all the links on the page (anchors) and saves them in a comma separated list. This list then gets split and pushed into an array. We then iterate through the list of links in the array clicking on each one and then navigating back to the starting page using go_back.
use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
my $sel = Test::WWW::Selenium->new( host => "localhost",
port => 4444,
browser => "*iexplore",
browser_url => "http://www.google.com/");
$sel->open_ok("/", "true");
$sel->set_speed("1000");
my $javascript = "var allLinks = this.browserbot.getCurrentWindow().document.getElementsByTagName('a');
var separator = ',';
var all_links_texts = '';
for(var i = 0; i < allLinks.length; i++) {
all_links_texts = all_links_texts+separator+allLinks[i].href;
}
all_links_texts;";
# Get all of the links in the page and, using a comma to separate each one, add them to the all_links_texts var.
my $link_list = $sel->get_eval($javascript);
my #link_array = split /,/ , $link_list;
my $count = 0;
# Click on each link contained in the array and then go_back
# You can add other logic here like capture and store a screenshot for example
foreach my $link_name (#link_array) {
unless ($link_name =~ /^$/){
$sel->click_ok("css=a[href $= $link_name]");
$sel->wait_for_page_to_load("30000");
print "Clicked Link href: $link_name \n";
$sel->go_back();
$count++;
}
}
print "Clicked $count URL's";
pass;
This can be easily modified to do much more than just click on the links. And of course nothing beats a good pair of eyes on the intended landing pages for the links clicked. Implementing a similar solution in your organization might ease with the manual testing. Here is how I have done it in the past:
Not everything can be automated, but we can certainly make it much easier to review large amounts of links. The above logic can be easily extended to capture a screen shot and add it to a queue of "to be reviewed" images. These properly tagged [by the software] images are what you use in the final phase of the test; visual verification phase.
With this approach you'll know right away if a link is broken or not (assuming you update the logic above to also include this, again this example can be easily extended to include that functionality). As well you will have the capability of visually verifying the screen shots of the intended link landing pages.
I actually have a blog post about this very same issue here: get all links and click on each one
Hope that helps.

Are data acquired from Facebook GRAPH API real-time?

I am creating a Facebook application that will download all the photos in an album. The application is created for my personal use and at the same time, learn the Facebook API and JSON.
I can already retrieve the URL of the photos inside an album by calling this url:
http://graph.facebook.com/[album id]/photos?fields=source
The album that I'm trying to download contains 5400+ photos so I tried increasing the limit by adding the limit parameter:
http://graph.facebook.com/[album id]/photos?fields=source&limit=1000
Here's the problem:
The results being returned are only until 2010-07-30T11:20:11+0000. When I tried to modify the query by using the until parameter like so:
http://graph.facebook.com/[album id]/photos?fields=source,link&limit=1000&until=2010-06-01
the data responded correctly. However, if I changed the date to something like 2010-08-05, the latest photo returned will have a created_date of 2010-07-30T11:20:11+0000.
The last photo returned is photo #5000 out of 5695.
Here's my question:
Is the data acquired from Facebook GRAPH Api real-time (or a Monthly update, 2010-07-30)? Or there's just a limit on the number of photos returned on album (like 5000)?
Thanks!
EDIT
There is a 5000 object limit in Facebook. If you know how to break the limit, go here:
Breaking the 5000 object limit in Facebook API
Thanks!
There is indeed 5000 limit on returned objects. You would need to run multiple FQL queries on photo table ordering and limiting the results (<5000) to get all the data (check photo table page for examples). (doesn't work)
When I look at the photos in the graph query you linked
https://graph.facebook.com/119403264763178/photos
I see paging information at the bottom. So, hacking together a quick test
$request = 'http://graph.facebook.com/119403264763178/photos?fields=source&limit=1000';
$response = json_decode( file_get_contents( $request ), true );
$totalCount = 0;
while ( count( $response['data'] ) )
{
echo 'Fetching ' . urldecode( $response['paging']['next'] ) . '<br>';
$totalCount += count( $response['data'] );
$response = json_decode( file_get_contents( $response['paging']['next'] ), true );
}
echo $totalCount;
It would seem that even following the paging data, you can still only retrieve 5000 records.
I'd suggest hitting up the FB forums or opening a bug ticket.