SpotifyWebAPI\Session::getAuthorizeUrl PHP Method

getAuthorizeUrl() public method

Get the authorization URL.
public getAuthorizeUrl ( array | object $options = [] ) : string
$options array | object Optional. Options for the authorization URL. - array scope Optional. Scope(s) to request from the user. - boolean show_dialog Optional. Whether or not to force the user to always approve the app. Default is false. - string state Optional. A CSRF token.
return string The authorization URL.
    public function getAuthorizeUrl($options = [])
    {
        $options = (array) $options;
        $parameters = ['client_id' => $this->getClientId(), 'redirect_uri' => $this->getRedirectUri(), 'response_type' => 'code', 'scope' => isset($options['scope']) ? implode(' ', $options['scope']) : null, 'show_dialog' => !empty($options['show_dialog']) ? 'true' : null, 'state' => isset($options['state']) ? $options['state'] : null];
        return Request::ACCOUNT_URL . '/authorize/?' . http_build_query($parameters);
    }

Usage Example

Example #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;
 }
All Usage Examples Of SpotifyWebAPI\Session::getAuthorizeUrl