Short Tag – Web Development Blog

Entries for the ‘Web Api’ Category

SoundCloud API – get number of followers

In order to get the number of followers of a user you have to:
1.) create a SoundCloud application:
2.) use this code in your website (and replace {$user_id} with your username, replace {$client_id} with the application’s Client id – displayed after you create the application):

$sc_content = file_get_contents("{$user_id}?consumer_key={$client_id}");
$sc_xml = simplexml_load_string($sc_content);

echo $sc_xml -> {‘followers-count’};

And that’s all!

Post to twitter with PHP, twitting with PHP

I wrote a post about using file_get_contents() in PHP with context stream a while ago. I thought I’d post a usage example. Below is a function that posts your message into your twitter profile directly from PHP.

function myTweet($username, $password, $msg)
$context = stream_context_create(array(
‘http’ => array(
‘method’  => ‘POST’,
‘header’  => sprintf("Authorization: Basic %s\r\n", base64_encode($username.’:’.$password)).
"Content-type: [...]