public function testRequestAccessToken() { $authorizationCode = 'd1e893a80f79d9ab5e7d322ed922da540964a63c'; $expected = array('client_id' => $this->clientID, 'client_secret' => $this->clientSecret, 'code' => $authorizationCode, 'grant_type' => 'authorization_code', 'redirect_uri' => $this->redirectURI); $return = array('body' => get_fixture('access-token')); $stub = $this->setupStub('POST', '/api/token', $expected, array(), $return); $session = new SpotifyWebAPI\Session($this->clientID, $this->clientSecret, $this->redirectURI, $stub); $result = $session->requestAccessToken($authorizationCode); $this->assertTrue($result); $this->assertNotEmpty($session->getAccessToken()); $this->assertNotEmpty($session->getRefreshToken()); $this->assertEquals(time() + 3600, $session->getTokenExpiration()); }
ini_set('display_errors', 'On'); require __DIR__ . '/../vendor/autoload.php'; use Firebase\Firebase; $fb = Firebase::initialize("https://boiling-fire-2669.firebaseio.com/", "P5Ofkmp3suKfnJWbWOtQimj5SqzC0tuWBdSz9UQh"); $root = $_SERVER['DOCUMENT_ROOT']; $session = new SpotifyWebAPI\Session('5bc1d4f975214ebb9be4698594970a18', 'ee1b5a43af9942b2adcf8f69532ae001', 'http://localhost:8888/confettiapp/server/spotify_auth.php'); $api = new SpotifyWebAPI\SpotifyWebAPI(); if (!isset($_SESSION)) { session_start(); } if (isset($_GET['authid'])) { $authid = $_GET['authid']; $_SESSION["authid"] = $authid; } if (isset($_GET['code'])) { $session->requestAccessToken($_GET['code']); $api->setAccessToken($session->getAccessToken()); $accessToken = $session->getAccessToken(); $refreshToken = $session->getRefreshToken(); $session->refreshAccessToken($refreshToken); $playlists = $api->getUserPlaylists('1113560298', array('limit' => 5)); if (isset($_SESSION["authid"])) { $authid_session = $_SESSION["authid"]; $fb_accesstoken = $fb->set("users/" . $authid_session . "/access_token", $accessToken); $fb_refreshtoken = $fb->set("users/" . $authid_session . "/refresh_token", $refreshToken); $user = $api->me(); $json = json_encode($user, true); $result = json_decode($json, true); $fb_username = $fb->set("users/" . $authid_session . "/sp_user", $result["id"]); echo "<script>window.close();</script>"; }