= 0.99.1)OAuth::fetch — 獲取一個 OAuth 受保護的資源說明public OAuth::fetch( string $protected_resource_url, array $extra_parameters">
(PECL OAuth >= 0.99.1)
OAuth::fetch — 獲取一個 OAuth 受保護的資源
$protected_resource_url,$extra_parameters = ?,$http_method = ?,$http_headers = ?獲取一個資源。
protected_resource_urlOAuth 受保護資源的URL
extra_parameters和資源請求一起發(fā)送的額外參數(shù)。
http_method
OAUTH_HTTP_METHOD_* 系列 OAUTH 常量之一,GET、POST、PUT、HEAD 或 DELETE 其中的一個。
HEAD (OAUTH_HTTP_METHOD_HEAD )可以用于先于請求發(fā)現(xiàn)信息(如果 OAuth 證書在 Authorization 頭部)。
http_headersHTTP 客戶端頭信息(像 User-Agent, Accept 等等這樣的)。
成功時返回 true, 或者在失敗時返回 false。
| 版本 | 說明 |
|---|---|
| 1.0.0 |
以前失敗時返回 null,而不是 false。
|
| 0.99.5 |
新增 http_method 參數(shù)
|
| 0.99.8 |
新增 http_headers 參數(shù)
|
示例 #1 OAuth::fetch() example
<?php
try {
$oauth = new OAuth("consumer_key","consumer_secret",OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauth->setToken("access_token","access_token_secret");
$oauth->fetch("http://photos.example.net/photo?file=vacation.jpg");
$response_info = $oauth->getLastResponseInfo();
header("Content-Type: {$response_info["content_type"]}");
echo $oauth->getLastResponse();
} catch(OAuthException $E) {
echo "Exception caught!\n";
echo "Response: ". $E->lastResponse . "\n";
}
?>