-
Notifications
You must be signed in to change notification settings - Fork 4
/
oPhpFlickr.php
65 lines (55 loc) · 2.06 KB
/
oPhpFlickr.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once(__DIR__.'/phpflickr/phpFlickr.php');
require_once(__DIR__.'/scribe-php/src/test/bootstrap.php');
class oPhpFlickr extends phpFlickr {
function __construct($api_key, $secret = NULL, $die_on_error = false) {
parent::__construct($api_key, $secret, $die_on_error);
$builder = new ServiceBuilder();
$this->oauth_service = $builder->provider(new FlickrApi())
->apiKey($api_key)
->apiSecret($secret)
->build();
}
function authorize_console() {
// Obtain the Request Token
$requestToken = $this->oauth_service->getRequestToken();
print("Go and authorize the application here:\n");
print($this->oauth_service->getAuthorizationUrl($requestToken) . "\n");
fwrite(STDOUT, "And paste the code you're given here: ");
$verifier = new Verifier(trim(fgets(STDIN)));
print("\n");
// Trade the Request Token and Verfier for the Access Token
$accessToken = $this->oauth_service->getAccessToken($requestToken, $verifier);
return $accessToken;
}
function request ($command, $args = array(), $nocache = false) {
// NOTE: cache not implemented
$args = array_merge(
array("url" => $this->rest_endpoint,
"method" => $command,
"format" => "json",
"nojsoncallback" => "1"),
$args);
$request = new OAuthRequest(Verb::POST, $args['url']);
foreach ($args as $key => $value) {
$request->addBodyParameter($key, $value);
}
$this->oauth_service->signRequest($this->token, $request);
$response_object = $request->send();
$response = $response_object->getBody();
$this->parsed_response = json_decode($response, TRUE);
if ($this->parsed_response['stat'] == 'fail') {
if ($this->die_on_error) die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}");
else {
$this->error_code = $this->parsed_response['code'];
$this->error_msg = $this->parsed_response['message'];
$this->parsed_response = false;
}
} else {
$this->error_code = false;
$this->error_msg = false;
}
return $response;
}
}
?>