Skip to content

Instantly share code, notes, and snippets.

@paulosman
Created January 26, 2013 22:08
Show Gist options
  • Save paulosman/4644946 to your computer and use it in GitHub Desktop.
Save paulosman/4644946 to your computer and use it in GitHub Desktop.
Using the password auth flow with the PHP SDK
<?php
require_once 'Services/Soundcloud.php';
$client = new Services_Soundcloud('A_VALID_CLIENT_ID', 'A_VALID_CLIENT_SECRET', 'REDIRECT_URI');
// manually construct URL-encoded request body. Note that if you use an email address
// as the username, you'll need to pass it through urlencode().
$options = "grant_type=password&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&username=<username>&password=<password>";
// $response will be an object with four properties: access_token, refresh_token, expires_in and scope
$response = json_decode($client->post('oauth2/token', $options));
// set the access token manually
$client->setAccessToken($response->access_token);
// ...
// $$$
print_r(json_decode($client->get('me')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment