begin_authentication() public méthode

public begin_authentication ( $callback )
Exemple #1
0
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
require_once '../rdio.php';
require_once 'rdio-consumer-credentials.php';
# create an instance of the Rdio object with our consumer credentials
$rdio = new Rdio(array(RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET));
# authenticate against the Rdio service
$url = $rdio->begin_authentication('oob');
print "Go to: {$url}\n";
print "Then enter the code: ";
$verifier = trim(fgets(STDIN));
$rdio->complete_authentication($verifier);
# find out what playlists you created
$myPlaylists = $rdio->call('getPlaylists')->result->owned;
# list them
foreach ($myPlaylists as $playlist) {
    print $playlist->shortUrl;
    print "\t";
    print $playlist->name;
    print "\n";
}
Exemple #2
0
  $protocol .= 's';
  $protocol_port = $_SERVER['SERVER_PORT'];
} else {
  $protocol_port = 80;
}
$host = $_SERVER['HTTP_HOST'];
$port = $_SERVER['SERVER_PORT'];
$request = $_SERVER['PHP_SELF'];
$query = substr($_SERVER['argv'][0], strpos($_SERVER['argv'][0], ';') + 1);
$BASEURL = $protocol . '://' . $host . ($port == $protocol_port ? '' : ':' . $port) . $request;


$op = $_GET["op"];
if($op == "login") {
  $callback_url = $BASEURL . '?op=login-callback';
  $auth_url = $rdio->begin_authentication($callback_url);
  header("Location: ".$auth_url);
} else if($op == "login-callback") {
  $rdio->complete_authentication($_GET["oauth_verifier"]);
  header("Location: ".$BASEURL);
} else if($op == "logout") {
  $rdio->logOut();
  header("Location: ".$BASEURL);
} else {
  if ($rdio->loggedIn()) {
    $person = $rdio->currentUser()->result;
    
    // make the API call
    $results = $rdio->search(
      array(
        "query" => $person->firstName,
's Playlists</h1>
      <ul><?php 
        $myPlaylists = $rdio->call('getPlaylists')->result->owned;
        # list them
        foreach ($myPlaylists as $playlist) {
            ?>
<li><a href="<?php 
            echo $playlist->shortUrl;
            ?>
"><?php 
            echo $playlist->name;
            ?>
</a></li><?php 
        }
        ?>
</ul><a href="?logout=1">Log out.</a><?php 
    } else {
        # auth failure, clear session
        session_destroy();
        # and start again
        header('Location: ' . $current_url);
    }
} else {
    # we have no authentication tokens.
    # ask the user to approve this app
    $authorize_url = $rdio->begin_authentication($current_url);
    # save the new token in our session
    $_SESSION['oauth_token'] = $rdio->token[0];
    $_SESSION['oauth_token_secret'] = $rdio->token[1];
    header('Location: ' . $authorize_url);
}