Skip to content

Commit de65cd3

Browse files
author
Jeff Hodsdon
committed
Example work
1 parent 4e9cfa2 commit de65cd3

16 files changed

+643
-63
lines changed

examples/access_token.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @link http://github.com/jeffhodsdon/HTTP_OAuth_Provider
2222
*/
2323

24+
require_once 'examples-config.php';
2425
include_once 'HTTP/OAuth/Consumer.php';
2526

2627
$consumer = new HTTP_OAuth_Consumer(
@@ -31,11 +32,17 @@
3132
);
3233

3334
try {
34-
$consumer->getAccessToken($config->access_token_url, $config->callback_url);
35-
$config->token = $consumer->getToken();
36-
$config->token_secret = $consumer->getTokenSecret();
35+
$consumer->getAccessToken($config->access_token_url, $config->verifier);
36+
echo json_encode(
37+
array(
38+
'token' => $consumer->getToken(),
39+
'token_secret' => $consumer->getTokenSecret()
40+
)
41+
);
3742
} catch (HTTP_OAuth_Consumer_Exception_InvalidResponse $e) {
3843
echo $e->getBody();
44+
} catch (Exception $e) {
45+
echo $e->getMessage();
3946
}
4047

4148
?>

examples/authorize_url.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
);
3232

3333
try {
34-
$config->authorize_url_result = $consumer->getAuthorizeUrl($config->authorize_url);
35-
} catch (HTTP_OAuth_Consumer_Exception_InvalidResponse $e) {
34+
echo $consumer->getAuthorizeUrl($config->authorize_url);
35+
} catch (Exception $e) {
3636
echo $e->getBody();
3737
}
3838

examples/cli.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,13 @@
2121
* @link http://github.com/jeffhodsdon/HTTP_OAuth_Provider
2222
*/
2323

24-
chdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
25-
26-
$base = realpath(dirname(__FILE__) . '/../../') . '/';
27-
set_include_path("{$base}HTTP_OAuth:{$base}HTTP_OAuth_Consumer:{$base}HTTP_OAuth_Provider:" . get_include_path());
24+
require_once 'config.php';
2825

2926
define(
3027
'USAGE',
3128
"Usage: php cli.php {method} [-{option}={value}, -{option}={value}, ...]\n"
3229
);
3330

34-
class Config
35-
{
36-
private $config = array();
37-
38-
public function __get($var)
39-
{
40-
if (!array_key_exists($var, $this->config)) {
41-
echo "Missing {$var} option\n";
42-
echo USAGE;
43-
die(0);
44-
}
45-
46-
return $this->config[$var];
47-
}
48-
49-
public function __set($var, $val)
50-
{
51-
$this->config[$var] = $val;
52-
}
53-
}
54-
5531
if (count($_SERVER['argv']) < 2) {
5632
echo USAGE;
5733
die(0);

examples/digg.gif

244 Bytes
Loading

examples/examples-config.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* HTTP_OAuth
4+
*
5+
* Implementation of the OAuth specification
6+
*
7+
* PHP version 5.2.0+
8+
*
9+
* LICENSE: This source file is subject to the New BSD license that is
10+
* available through the world-wide-web at the following URI:
11+
* http://www.opensource.org/licenses/bsd-license.php. If you did not receive
12+
* a copy of the New BSD License and are unable to obtain it through the web,
13+
* please send a note to [email protected] so we can mail you a copy immediately.
14+
*
15+
* @category HTTP
16+
* @package HTTP_OAuth
17+
* @author Jeff Hodsdon <[email protected]>
18+
* @copyright 2009 Jeff Hodsdon <[email protected]>
19+
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
20+
* @link http://pear.php.net/package/HTTP_OAuth_Provider
21+
* @link http://github.com/jeffhodsdon/HTTP_OAuth_Provider
22+
*/
23+
24+
chdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
25+
26+
$base = realpath(dirname(__FILE__) . '/../../') . '/';
27+
set_include_path("{$base}HTTP_OAuth:{$base}HTTP_OAuth_Consumer:{$base}HTTP_OAuth_Provider:" . get_include_path());
28+
29+
/* Configuration for Examples */
30+
31+
class Config
32+
{
33+
private $config = array();
34+
35+
public $isHttp = false;
36+
37+
public function __get($var)
38+
{
39+
if (!array_key_exists($var, $this->config)) {
40+
if ($this->isHttp) {
41+
header('HTTP/1.1 500 Internal Server Error');
42+
}
43+
44+
echo "Missing {$var} option\n";
45+
die(0);
46+
}
47+
48+
return $this->config[$var];
49+
}
50+
51+
public function __set($var, $val)
52+
{
53+
$this->config[$var] = $val;
54+
}
55+
}
56+
57+
$config = new Config;
58+
if (!empty($_GET)) {
59+
$config->isHttp = true;
60+
foreach ($_GET as $name => $val) {
61+
if (!strlen($val)) {
62+
continue;
63+
}
64+
65+
$config->$name = $val;
66+
}
67+
}
68+
69+
?>

examples/google.gif

385 Bytes
Loading

0 commit comments

Comments
 (0)