OAuth 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
리소스를 가져옵니다.
매개변수
protected_resource_url
- OAuth 보호 리소스에 대한 URL입니다.
extra_parameters
- 리소스 요청과 함께 보낼 추가 매개변수입니다.
http_method
- GET, POST, PUT, HEAD 또는 DELETE를 포함하는
OAUTH_HTTP_METHOD_*
OAUTH constants 중 하나입니다.HEAD(
OAUTH_HTTP_METHOD_HEAD
)는 요청 전에 정보를 검색하는 데 유용할 수 있습니다(OAuth 자격 증명이Authorization
header에 있는 경우). http_headers
- HTTP 클라이언트 헤더(예: User-Agent, Accept 등)
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
변경 로그
버전 | 설명 |
---|---|
PECL oauth 1.0.0 | 이전에는 실패 시 false 대신 null 을 반환했습니다. |
PECL oauth 0.99.5 | http_method 매개변수가 추가되었습니다. |
PECL oauth 0.99.8 | http_headers 매개변수가 추가되었습니다. |
Examples
예제 #1 OAuth::fetch() 예제
<?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";
}
?>
기타
- OAuth::getLastResponse() - 마지막 응답 받기
- OAuth::getLastResponseInfo() - 마지막 응답에 대한 HTTP 정보 가져오기
- OAuth::setToken() - 토큰과 비밀을 설정합니다