setAccessToken() public méthode

Set the access token to use.
public setAccessToken ( string $accessToken ) : void
$accessToken string The access token.
Résultat void
Exemple #1
0
 public static function connect($accessToken)
 {
     static::assertValidAccessToken($accessToken);
     $api = new SpotifyWebAPI();
     $api->setAccessToken($accessToken);
     return new static($api);
 }
 public function register(Application $app)
 {
     $app['spotify.api'] = $app->share(function () use($app) {
         $api = new ThirdPartApi();
         if (!($auth_token = $app['predis']->get('spotify:auth'))) {
             $session = new \SpotifyWebAPI\Session(Credentials::CLIENT_ID, Credentials::CLIENT_SECRET, '');
             $session->requestCredentialsToken(array());
             $auth_token = $session->getAccessToken();
             $app['predis']->set('spotify:auth', $auth_token);
             $app['predis']->expire('spotify:auth', $session->getExpires() - 60);
         }
         $api->setAccessToken($auth_token);
         return new RuntimeCacheDecorator(new SpotifyApi($api));
     });
 }
Exemple #3
0
 /**
  * (non-PHPdoc)
  * @see \API\src\Endpoints\Endpoints::get()
  */
 public function get()
 {
     $session = new Session(Config::getConfig('SpotifyAppId'), Config::getConfig('SpotifySecret'));
     $callback = 'http://api.soundeavor.com/User/Auth/Login/Spotify/index.php';
     $session->setRedirectUri($callback);
     $url = $session->getAuthorizeUrl();
     if (!isset($_GET['code'])) {
         header('Location: ' . $url);
     }
     $code = $_GET['code'];
     $api = new SpotifyWebAPI();
     $session->requestToken($code);
     $api->setAccessToken($session->getAccessToken());
     $me = $api->me();
     $body['spotifyName_text'] = $me->display_name;
     $body['spotifyAccessToken_text'] = $session->getAccessToken();
     $body['spotifyUserId_text'] = $me->id;
     $this->request->response->body = $body;
     $this->request->response->code = r_success;
 }
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function showPlaylistList(Request $request)
 {
     $session = new SpotifyWebAPI\Session(Config::get('spotify.client_id'), Config::get('spotify.client_secret'), Config::get('spotify.redirect_url.showPlaylistList'));
     $api = new SpotifyWebAPI\SpotifyWebAPI();
     try {
         if (isset($_GET['code'])) {
             $session->requestAccessToken($_GET['code']);
             $api->setAccessToken($session->getAccessToken());
         } else {
             header('Location: ' . $session->getAuthorizeUrl(array('scope' => array('playlist-modify-private', 'playlist-modify-public', 'playlist-read-private'))));
             die;
         }
     } catch (Exception $e) {
         Log::error($e->getMessage());
         return redirect('/spotify/step_one');
     }
     if (!$request->session()->get('spotify.user_id') && $request->session()->get('spotify.playlist_id')) {
         return redirect('/spotify/step_one');
     }
     $playlistTracks = $api->getUserPlaylistTracks($request->session()->get('spotify.user_id'), $request->session()->get('spotify.playlist_id'));
     $spotifyPlaylist = array();
     $data = array();
     foreach ($playlistTracks->items as $track) {
         $track = $track->track;
         $spotifyPlaylist[$track->id] = $track->name . ' ' . $track->artists[0]->name;
         $data[] = array('id' => $track->id, 'name' => $track->name, 'artists' => $track->artists[0]->name);
     }
     $request->session()->put('spotify.songs', $spotifyPlaylist);
     return View::make('spotify.step_four')->with('data', $data);
 }