ホーム > 日記 > PEAR:HTTP_OAuth_Consumer_Response::getDataFromBody()

PEAR:HTTP_OAuth_Consumer_Response::getDataFromBody()

PEAR::HTTP_OAuthでxAuth

require_once ‘HTTP/Request2.php’;
require_once ‘HTTP/OAuth/Consumer.php’;
$consumer_key           = ‘YOUR-CONSUMER-KEY’;
$consumer_secret        = ‘YOUR-CONSUMER-SECRET’;
$username               = ‘YOUR-USER-NAME’;
$password               = ‘YOUR-PASSWORD’;
$xauth_access_token_url = ‘https://api.twitter.com/oauth/access_token’;
$params = array(
  ‘x_auth_username’ => $username,
  ‘x_auth_password’ => $password,
  ‘x_auth_mode’     => ‘client_auth’,
);
try {
  $request = new HTTP_Request2();
  $request->setConfig(’ssl_verify_peer’, false);
  $consumerRequest = new HTTP_OAuth_Consumer_Request();
  $consumerRequest->accept($request);
  $oauth = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
  $oauth->accept($consumerRequest);
  $response = $oauth->sendRequest($xauth_access_token_url,
                                  $params,
                                  HTTP_Request2::METHOD_POST);
  $data = $response->getDataFromBody();
  // oauth_token, oauth_token_secret, user_id, screen_name, x_auth_expire
  var_dump($data);
} catch (HTTP_OAuth_Exception $e) {
  echo $e->toText();
  exit;
}
カテゴリー: 日記 タグ:
  1. コメントはまだありません。
  1. トラックバックはまだありません。