/
TwitterOAuthUtility.class.php
41 lines (35 loc) · 1.11 KB
/
TwitterOAuthUtility.class.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
<?
/*
* Ensure we have TwitterOAuth class to inherit from.
* TwitterOAuth must be in the include_path.
*/
require_once("twitteroauth/twitteroauth/twitteroauth.php");
/*
* Utility class to construct OAuth-signed URLs.
*/
class TwitterOAuthUtility extends TwitterOAuth {
protected $buffer;
/*
* Allow overriding API host URL.
* This is actually the URL root - e.g.
* http://api.twitter.com/1/, or
* https://userstream.twitter.com/2/
* as in the user stream.
*/
function setHost($newHost) {
$this->host = $newHost;
}
function getOAuthUrl($url, $method, $parameters = array()) {
$request = $this->createOAuthRequest($url, $method, $parameters);
return $request->to_url();
}
function createOAuthRequest($url, $method, $parameters) {
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
$url = "{$this->host}{$url}.{$this->format}";
}
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
$request->sign_request($this->sha1_method, $this->consumer, $this->token);
return $request;
}
}
?>