OAuth::fetch

(PECL OAuth >= 0.99.1)

OAuth::fetchObtiene un recurso protegido por OAuth

Descripción

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

Obtiene un recurso.

Parámetros

protected_resource_url

URL del recurso OAuth protegio.

extra_parameters

Parámetros adicionales para enviar con la petición del recurso.

http_method

Una de las OAUTH_HTTP_METHOD_*constantes OAUTH, which includes GET, POST, PUT, HEAD, or DELETE.

HEAD (OAUTH_HTTP_METHOD_HEAD) can be useful for discovering information prior to the request (if OAuth credentials are in the Authorization header).

http_headers

Encabezados cliente HTTP (como por ejemplo User-Agent, Accept, etc.)

Valores devueltos

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

Historial de cambios

VersiónDescripción
1.0.0 Antes devolvía null en caso de falla, en lugar de false.
0.99.5 El parámetro http_method fue agregado
0.99.8 El parámetro http_headers fue agregado

Ejemplos

Ejemplo #1 Ejemplo de 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
"Excepción atrapada!\n";
echo
"Respuesta: ". $E->lastResponse . "\n";
}
?>

Ver también

To Top