Exemplo n.º 1
0
/**
 * getSpotifyWebAPI function.
 *
 * @access public
 * @param mixed $w
 * @return void
 */
function getSpotifyWebAPI($w, $old_api = null)
{
    if (!$w->internet()) {
        throw new SpotifyWebAPI\SpotifyWebAPIException("No internet connection", 100);
    }
    //
    // Read settings from JSON
    //
    $settings = getSettings($w);
    $oauth_client_id = $settings->oauth_client_id;
    $oauth_client_secret = $settings->oauth_client_secret;
    $oauth_redirect_uri = $settings->oauth_redirect_uri;
    $oauth_access_token = $settings->oauth_access_token;
    $oauth_expires = $settings->oauth_expires;
    $oauth_refresh_token = $settings->oauth_refresh_token;
    if ($old_api == null) {
        // create a new api object
        $session = new SpotifyWebAPI\Session($oauth_client_id, $oauth_client_secret, $oauth_redirect_uri);
        $session->setRefreshToken($oauth_refresh_token);
        $api = new SpotifyWebAPI\SpotifyWebAPI();
    }
    // Check if refresh token necessary
    // if token validity < 20 minutes
    if (time() - $oauth_expires > 2400) {
        if ($old_api != null) {
            // when refresh needed:
            // create a new api object (even if api not null)
            $session = new SpotifyWebAPI\Session($oauth_client_id, $oauth_client_secret, $oauth_redirect_uri);
            $session->setRefreshToken($oauth_refresh_token);
            $api = new SpotifyWebAPI\SpotifyWebAPI();
        }
        if ($session->refreshToken() == true) {
            $oauth_access_token = $session->getAccessToken();
            // Set new token to settings
            $ret = updateSetting($w, 'oauth_access_token', $oauth_access_token);
            if ($ret == false) {
                throw new SpotifyWebAPI\SpotifyWebAPIException("Cannot set oauth_access_token", 100);
            }
            $ret = updateSetting($w, 'oauth_expires', time());
            if ($ret == false) {
                throw new SpotifyWebAPI\SpotifyWebAPIException("Cannot set oauth_expires", 100);
            }
            $api->setAccessToken($oauth_access_token);
        } else {
            throw new SpotifyWebAPI\SpotifyWebAPIException("Token could not be refreshed", 100);
        }
    } else {
        // no need to refresh, the old api is
        // stil valid
        if ($old_api != null) {
            $api = $old_api;
        } else {
            // set the access token for the new api
            $api->setAccessToken($oauth_access_token);
        }
    }
    return $api;
}
Exemplo n.º 2
0
<?php

error_reporting(E_ALL);
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);
require_once './src/workflows.php';
$w = new Workflows('com.vdesabou.spotify.mini.player');
//
// Read settings from JSON
//
$settings = getSettings($w);
$oauth_client_id = $settings->oauth_client_id;
$oauth_client_secret = $settings->oauth_client_secret;
$oauth_redirect_uri = $settings->oauth_redirect_uri;
try {
    $session = new SpotifyWebAPI\Session($oauth_client_id, $oauth_client_secret, $oauth_redirect_uri);
    if (!empty($_GET['code'])) {
        // Request a access token using the code from Spotify
        $ret = $session->requestAccessToken($_GET['code']);
        if ($ret == true) {
            $api = new SpotifyWebAPI\SpotifyWebAPI();
            // Set the code on the API wrapper
            $api->setAccessToken($session->getAccessToken());
            $user = $api->me();
            $ret = updateSetting($w, 'oauth_access_token', $session->getAccessToken());
            if ($ret == false) {
                echo "There was an error when updating settings";
                exec("kill -9 \$(ps -efx | grep \"php -S localhost:15298\"  | grep -v grep | awk '{print \$2}')");
                return;
            }
            $ret = updateSetting($w, 'oauth_expires', time());
            if ($ret == false) {
                echo "There was an error when updating settings";
                exec("kill -9 \$(ps -efx | grep \"php -S localhost:15298\"  | grep -v grep | awk '{print \$2}')");
                return;
            }
 public function testUserFollowsPlaylist()
 {
     $options = array('ids' => array('74ASZWbe4lXaubB36ztrGX', '36QJpDe2go2KgaRleHCDTp'));
     $expected = array('ids' => '74ASZWbe4lXaubB36ztrGX,36QJpDe2go2KgaRleHCDTp');
     $headers = array('Authorization' => 'Bearer ' . $this->accessToken);
     $return = array('body' => get_fixture('users-follows-playlist'));
     $stub = $this->setupStub('GET', '/v1/users/mcgurk/playlists/0UZ0Ll4HJHR7yvURYbHJe9/followers/contains', $expected, $headers, $return);
     $api = new SpotifyWebAPI\SpotifyWebAPI($stub);
     $api->setAccessToken($this->accessToken);
     $response = $api->userFollowsPlaylist('mcgurk', '0UZ0Ll4HJHR7yvURYbHJe9', $options);
     $this->assertTrue($response[0]);
 }
Exemplo n.º 5
0
{
    $url_hash = md5($url);
    if (file_exists($url_hash)) {
        return file_get_contents($url_hash);
    } else {
        $content = file_get_contents($url);
        file_put_contents($url_hash, $content);
        return $content;
    }
}
include __DIR__ . '/qp/qp.php';
require __DIR__ . '/spotify-web-api-php-master/src/SpotifyWebAPI.php';
require __DIR__ . '/spotify-web-api-php-master/src/Request.php';
require __DIR__ . '/spotify-web-api-php-master/src/Session.php';
require __DIR__ . '/spotify-web-api-php-master/src/SpotifyWebAPIException.php';
$api = new SpotifyWebAPI\SpotifyWebAPI();
$pages = array('https://pro.beatport.com/genre/deep-house/12/tracks');
$done = array();
$final_page = isset($_GET['pages']) ? $_GET['pages'] : 1;
//echo '<pre>';
$ipCount = 0;
while ($pages) {
    set_time_limit(0);
    $link = array_shift($pages);
    $done[] = $link;
    //$content = file_get_contents($link);
    $content = getFile($link);
    //load qp with content fetched and initialise from body tag
    $htmlqp = @htmlqp($content, 'body');
    if ($htmlqp->length > 0) {
        //we have some data to parse.
Exemplo n.º 6
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'))));
}
Exemplo n.º 7
0
<?php

require 'vendor/autoload.php';
require 'model.php';
use Symfony\Component\HttpFoundation\Request;
$api = new SpotifyWebAPI\SpotifyWebAPI();
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/views'));
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
//$app['asset_path'] = 'C:\xampp\htdocs\gtunes';
//obtenir des infos de track par item 'track' et des mots clés
$app->get('/api/search/track/{name}', function ($name) use($app, $api) {
    session_start();
    if (empty($_SESSION['valid_userid'])) {
        header("location:loginerror.php");
        exit;
    }
    $name_user = $_SESSION['valid_username'];
    $id_user = $_SESSION['valid_userid'];
    $results = $api->search($name, 'track');
    return $app['twig']->render('result_by_track.html.twig', array('results' => $results, 'name_user' => $name_user, 'id_user' => $id_user));
});
////obtenir des infos d'artist par item 'artist' et des mots clés
$app->get('/api/search/artist/{name}', function ($name) use($api, $app) {
    session_start();
    if (empty($_SESSION['valid_userid'])) {
        header("location:loginerror.php");
        exit;
    }
    $name_user = $_SESSION['valid_username'];
Exemplo n.º 8
0
<?php

require 'vendor/autoload.php';
use Acme\Args;
use Acme\Output;
// init everything!
$config = Spyc::YAMLLoad('config.yaml');
$args = new Args();
$googleClient = new Google_Client();
$googleClient->setDeveloperKey($config['google_developer_key']);
$youtube = new Google_Service_YouTube($googleClient);
$spotifyAPI = new SpotifyWebAPI\SpotifyWebAPI();
// set those
date_default_timezone_set($config['timezone']);
set_exception_handler(['Acme\\Error', 'handle']);
// for debug
if (gethostname() === 'CodeBrauer.local') {
    include '../ref/ref.php';
}
$args->check();
list($url, $arg2) = $args->process();
// action start
if ($arg2 == 'only-uri') {
    ob_start();
}
$nextPageToken = null;
do {
    $playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array('playlistId' => rawurlencode($url), 'maxResults' => 50, 'pageToken' => $nextPageToken));
    foreach ($playlistItemsResponse['items'] as $playlistItem) {
        $trackName = str_ireplace($config['ignore_video_title'], '', $playlistItem['snippet']['title']);
        $search = $spotifyAPI->search(trim($trackName), 'track');
Exemplo n.º 9
0
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
$session = new SpotifyWebAPI\Session('2888525482b94ccb86ae7ee9469bab07', '6df8e93ea2ba49c6ae90951fea0e2f9e', 'http://confetti:8888/details.php');
$api = new SpotifyWebAPI\SpotifyWebAPI();
// Request a access token using the code from Spotify
$session->requestAccessToken($_GET['code']);
$accessToken = $session->getAccessToken();
$refreshToken = $session->getRefreshToken();
// Set the access token on the API wrapper
$api->setAccessToken($accessToken);
$session->refreshAccessToken($refreshToken);
// Start using the API!
// $add = $api->addUserPlaylistTracks('1113560298', '7Fyg5tJ0oQdIRxLwOJ2T1g', array(
//     '0sr5LOMv4x0jmTYfe6oOvP',
// ));
if ($accessToken) {
    $data = array('access_token' => $accessToken, 'refresh_token' => $refreshToken);
    echo json_encode($data);
} else {
    echo "Can't authorize";
}
 public function testSetReturnAssoc()
 {
     $request = $this->getMock('SpotifyWebAPI\\Request');
     $request->expects($this->once())->method('setReturnAssoc')->with(true);
     $api = new SpotifyWebAPI\SpotifyWebAPI($request);
     $api->setReturnAssoc(true);
 }
Exemplo n.º 11
0


<?php 
require 'vendor/autoload.php';
$api = new SpotifyWebAPI\SpotifyWebAPI();
$tracks = $api->getArtist('0OdUWJ0sBjDrqHygGUXeCF');
print_r($tracks);