OAuth::fetch

(PECL OAuth >= 0.99.1)

OAuth::fetchLee un recurso protegido por OAuth

Descripción

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

Lee un recurso protegido por OAuth.

Parámetros

protected_resource_url

URL del recurso protegido por OAuth.

extra_parameters

Argumentos adicionales a enviar con la petición, al recurso.

http_method

Una de las constantes OAUTH constants OAUTH_HTTP_METHOD_*, incluyendo GET, POST, PUT, HEAD, o DELETE.

HEAD (OAUTH_HTTP_METHOD_HEAD) puede ser útil para descubrir información antes de la petición (si las autorizaciones OAuth están en el encabezado Authorization).

http_headers

Los encabezados HTTP del cliente (tales como User-Agent, Accept, etc.)

Valores devueltos

Devuelve true en caso de éxito o false en caso de error.

Historial de cambios

Versión Descripción
PECL oauth 1.0.0 Antes devolvía null en caso de falla, en lugar de false.
PECL oauth 0.99.5 Se añadió el argumento http_method
PECL oauth 0.99.8 Se añadió el argumento http_headers

Ejemplos

Ejemplo #1 Ejemplo con 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";
}
?>

Ver también