Skip to content

Commit

Permalink
use regular php tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bdougherty committed Sep 7, 2010
1 parent 5e66fd9 commit 67f1410
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 86 deletions.
132 changes: 66 additions & 66 deletions index.php
@@ -1,4 +1,4 @@
<?
<?php
require_once('vimeo.php');
session_start();

Expand All @@ -8,8 +8,8 @@

// Clear session
if ($_GET['clear'] == 'all') {
session_destroy();
session_start();
session_destroy();
session_start();
}

// Set up variables
Expand All @@ -19,84 +19,84 @@

// Coming back
if ($_REQUEST['oauth_token'] != NULL && $_SESSION['vimeo_state'] === 'start') {
$_SESSION['vimeo_state'] = $state = 'returned';
$_SESSION['vimeo_state'] = $state = 'returned';
}

// If we have an access token, set it
if ($_SESSION['oauth_access_token'] != null) {
$vimeo->setToken($_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
$vimeo->setToken($_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
}

switch ($_SESSION['vimeo_state']) {
default:
// Get a new request token
$token = $vimeo->getRequestToken();
// Store it in the session
$_SESSION['oauth_request_token'] = $token['oauth_token'];
$_SESSION['oauth_request_token_secret'] = $token['oauth_token_secret'];
$_SESSION['vimeo_state'] = 'start';
// Build authorize link
$authorize_link = $vimeo->getAuthorizeUrl($token['oauth_token'], 'write');
break;
case 'returned':
// Store it
if ($_SESSION['oauth_access_token'] === NULL && $_SESSION['oauth_access_token_secret'] === NULL) {
// Exchange for an access token
$vimeo->setToken($_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']);
$token = $vimeo->getAccessToken($_REQUEST['oauth_verifier']);
// Store
$_SESSION['oauth_access_token'] = $token['oauth_token'];
$_SESSION['oauth_access_token_secret'] = $token['oauth_token_secret'];
$_SESSION['vimeo_state'] = 'done';
// Set the token
$vimeo->setToken($_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
}
// Do an authenticated call
try {
$videos = $vimeo->call('vimeo.videos.getUploaded');
}
catch (VimeoAPIException $e) {
echo "Encountered an API error -- code {$e->getCode()} - {$e->getMessage()}";
}
break;
default:

// Get a new request token
$token = $vimeo->getRequestToken();

// Store it in the session
$_SESSION['oauth_request_token'] = $token['oauth_token'];
$_SESSION['oauth_request_token_secret'] = $token['oauth_token_secret'];
$_SESSION['vimeo_state'] = 'start';

// Build authorize link
$authorize_link = $vimeo->getAuthorizeUrl($token['oauth_token'], 'write');

break;

case 'returned':

// Store it
if ($_SESSION['oauth_access_token'] === NULL && $_SESSION['oauth_access_token_secret'] === NULL) {
// Exchange for an access token
$vimeo->setToken($_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']);
$token = $vimeo->getAccessToken($_REQUEST['oauth_verifier']);

// Store
$_SESSION['oauth_access_token'] = $token['oauth_token'];
$_SESSION['oauth_access_token_secret'] = $token['oauth_token_secret'];
$_SESSION['vimeo_state'] = 'done';

// Set the token
$vimeo->setToken($_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
}

// Do an authenticated call
try {
$videos = $vimeo->call('vimeo.videos.getUploaded');
}
catch (VimeoAPIException $e) {
echo "Encountered an API error -- code {$e->getCode()} - {$e->getMessage()}";
}

break;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Vimeo Advanced API OAuth Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Vimeo Advanced API OAuth Example</title>
</head>
<body>
<h1>Vimeo Advanced API OAuth Example</h1>
<p>This is a basic example of Vimeo's new OAuth authentication method. Everything is saved in session vars, so <a href="?clear=all">click here if you want to start over</a>.</p>
<? if ($_SESSION['vimeo_state'] == 'start'): ?>
<p>Click the link to go to Vimeo to authorize your account.</p>
<p><a href="<?= $authorize_link ?>"><?= $authorize_link ?></a></p>
<? endif ?>
<? if ($ticket): ?>
<pre><? print_r($ticket) ?></pre>
<? endif ?>
<? if ($videos): ?>
<pre><? print_r($videos) ?></pre>
<? endif ?>

<h1>Vimeo Advanced API OAuth Example</h1>
<p>This is a basic example of Vimeo's new OAuth authentication method. Everything is saved in session vars, so <a href="?clear=all">click here if you want to start over</a>.</p>

<?php if ($_SESSION['vimeo_state'] == 'start'): ?>
<p>Click the link to go to Vimeo to authorize your account.</p>
<p><a href="<?= $authorize_link ?>"><?php echo $authorize_link ?></a></p>
<?php endif ?>

<?php if ($ticket): ?>
<pre><?php print_r($ticket) ?></pre>
<?php endif ?>

<?php if ($videos): ?>
<pre><?php print_r($videos) ?></pre>
<?php endif ?>

</body>
</html>
32 changes: 15 additions & 17 deletions upload.php
@@ -1,24 +1,22 @@
<?
<?php
include 'vimeo.php';

$vimeo = new phpVimeo('CONSUMER_KEY', 'CONSUMER_SECRET', 'ACCESS_TOKEN', 'ACCESS_TOKEN_SECRET');

try {
$video_id = $vimeo->upload('PATH_TO_VIDEO_FILE');
if ($video_id) {
echo '<a href="http://vimeo.com/' . $video_id . '">Upload successful!</a>';
//$vimeo->call('vimeo.videos.setPrivacy', array('privacy' => 'nobody', 'video_id' => $video_id));
$vimeo->call('vimeo.videos.setTitle', array('title' => 'YOUR TITLE', 'video_id' => $video_id));
$vimeo->call('vimeo.videos.setDescription', array('description' => 'YOUR_DESCRIPTION', 'video_id' => $video_id));
}
else {
echo "Video file did not exist!";
}
$video_id = $vimeo->upload('PATH_TO_VIDEO_FILE');

if ($video_id) {
echo '<a href="http://vimeo.com/' . $video_id . '">Upload successful!</a>';

//$vimeo->call('vimeo.videos.setPrivacy', array('privacy' => 'nobody', 'video_id' => $video_id));
$vimeo->call('vimeo.videos.setTitle', array('title' => 'YOUR TITLE', 'video_id' => $video_id));
$vimeo->call('vimeo.videos.setDescription', array('description' => 'YOUR_DESCRIPTION', 'video_id' => $video_id));
}
else {
echo "Video file did not exist!";
}
}
catch (VimeoAPIException $e) {
echo "Encountered an API error -- code {$e->getCode()} - {$e->getMessage()}";
}

?>
echo "Encountered an API error -- code {$e->getCode()} - {$e->getMessage()}";
}
4 changes: 1 addition & 3 deletions vimeo.php
@@ -1,4 +1,4 @@
<?
<?php
class phpVimeo
{
const API_REST_URL = 'http://vimeo.com/api/rest/v2';
Expand Down Expand Up @@ -540,5 +540,3 @@ public static function url_encode_rfc3986($input)
}

class VimeoAPIException extends Exception {}

?>

0 comments on commit 67f1410

Please sign in to comment.