public function testMe()
 {
     $headers = array('Authorization' => 'Bearer ' . $this->accessToken);
     $return = array('body' => get_fixture('user'));
     $stub = $this->setupStub('GET', '/v1/me', array(), $headers, $return);
     $api = new SpotifyWebAPI\SpotifyWebAPI($stub);
     $api->setAccessToken($this->accessToken);
     $response = $api->me();
     $this->assertObjectHasAttribute('id', $response);
 }
Esempio n. 2
0
    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>";
    }
} else {
    header('Location: ' . $session->getAuthorizeUrl(array('scope' => array('user-follow-modify', 'user-follow-read', 'user-read-email', 'user-read-private', 'playlist-modify-private', 'playlist-modify-public', 'playlist-read-private'))));
    die;
}
// $api->replaceUserPlaylistTracks('USER_ID', 'PLAYLIST_ID', array(
//     '0eGsygTp906u18L0Oimnem',
//     '1lDWb6b6ieDQ2xT7ewTC3G'
// ));
Esempio n. 3
0
<?php

error_reporting(-1);
ini_set('display_errors', 1);
require 'vendor/autoload.php';
Dotenv::load(__DIR__);
$session = new SpotifyWebAPI\Session(getenv('SPOTIFY_CLIENT_ID'), getenv('SPOTIFY_CLIENT_SECRET'), getenv('SPOTIFY_REDIRECT_URI'));
$api = new SpotifyWebAPI\SpotifyWebAPI();
if (isset($_GET['code'])) {
    $session->requestToken($_GET['code']);
    $api->setAccessToken($session->getAccessToken());
    print_r($api->me());
} else {
    header('Location: ' . $session->getAuthorizeUrl(array('scope' => array('user-read-email', 'user-library-modify'))));
}