= 0.99.1)OAuth::fetch — 獲取一個 OAuth 受保護的資源說明public OAuth::fetch( string $protected_resource_url, array $extra_parameters">

OAuth::fetch

(PECL OAuth >= 0.99.1)

OAuth::fetch獲取一個 OAuth 受保護的資源

說明

public OAuth::fetch(
    string $protected_resource_url,
    array $extra_parameters = ?,
    string $http_method = ?,
    array $http_headers = ?
): mixed

獲取一個資源。

參數(shù)

protected_resource_url

OAuth 受保護資源的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_headers

HTTP 客戶端頭信息(像 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";
}
?>

參見