Beispiel #1
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);
 }