/** * @param string $clientId * @param string $clientSecret * @param string $redirectUrl * @param string $state * * @return Bitly */ public static function authorize($clientId, $clientSecret, $redirectUrl, $state = null) { if (isset($_GET['code']) && $_GET['code']) { $instance = new self(); $instance->_getAccessTokenCode($clientId, $clientSecret, $_GET['code'], $redirectUrl); return $instance; } else { $data = ['client_id' => $clientId, 'redirect_uri' => $redirectUrl, 'state' => $state]; $url = 'https://bitly.com/oauth/authorize?' . http_build_query($data); header('Location: ' . $url); exit; } }