先ほどのGitHubサンプルほどまとまってはいませんm(_ _)m
http://madroom-project.blogspot.jp/2013/02/fuelphpgithub.html
まず、SoundCloudのアプリは
http://soundcloud.com/you/apps/new
で登録できます。
アプリを登録すると、Client IDとClient Secretが手に入ります。
PHP用のSoundCloudライブラリは
https://github.com/mptre/php-soundcloud
を使いました。app/vendor/soundcloudとして配置しました。
以下、コントローラのサンプルです。$codeのチェックとか入っていませんが、要点はこんな感じなのかなと思います。
<?php
require_once APPPATH.'vendor'.DS.'soundcloud'.DS.'Services'.DS.'Soundcloud.php';
class Controller_Soundcloud extends Controller
{
private static $client_id = 'xxxxxxxxxx';
private static $client_secret = 'yyyyyyyyyy';
public function action_signin()
{
$client = new Services_Soundcloud(
static::$client_id,
static::$client_secret,
Uri::create('soundcloud/callback'));
Response::redirect($client->getAuthorizeUrl());
}
public function action_callback()
{
$client = new Services_Soundcloud(
static::$client_id,
static::$client_secret,
Uri::create('soundcloud/callback'));
$code = Input::get('code', false);
$access_token = $client->accessToken($code);
$client->setAccessToken($access_token['access_token']);
$me = $client->get('me');
// 期限切れ対策のメモ
$new_access_token = $client->accessTokenRefresh($access_token['refresh_token']);
Debug::dump($access_token, json_decode($me), $new_access_token);
exit();
}
}
そのうち、もう少しまとめたいとは思います。。。パッと見、ドキュメントにscopeの指定が見当たらないです。
http://developers.soundcloud.com/docs/api/guide
もしかして認証 = 全権限??
No comments:
Post a Comment