OAuth H9 Google Health

时间:2010-08-25 19:54:33

标签: oauth google-health

我试图获得三条腿的Oauth访问权限,但我无法迈出第一步。到目前为止我的代码:

include("OAuth.php");
$consumer_key = "anonymous";
$consumer_secret = "anonymous";

define("URI", "http://www.google.com");
$request_token_url  = URI.'/accounts/OAuthGetRequestToken?scope=https%3A%2F%2Fwww.google.com%2Fh9%2Ffeeds%2F';
$parsed = parse_url($request_token_url);
$params = array();

$oauth_consumer = new OAuthConsumer($consumer_key, $consumer_secret, NULL);
$req_req = OAuthRequest::from_consumer_and_token($oauth_consumer, NULL, "GET", $request_token_url, $params);

$sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$req_req->sign_request($sig_method, $oauth_consumer, NULL);

$request  = $req_req->to_url();
$session = curl_init($request);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
// Make the request
$response = curl_exec($session);

//Error Handling:
// there is an error while executing the request, 
if (!$response) {  
  $response = curl_error($curl);  
}  
curl_close($session);

parse_str($response, $params);
$oauth_token = $params['oauth_token'];
$oauth_token_secret = $params['oauth_token_secret'];
$_SESSION['CONSUMER_KEY'] = $consumer_key;
$_SESSION['CONSUMER_SECRET'] = $consumer_secret;
$_SESSION['REQUEST_TOKEN'] = $oauth_token;
$_SESSION['REQUEST_TOKEN_SECRET'] = $oauth_token_secret;

print_r($_SESSION);

我正在使用OAuth.php

返回的数组没有给我任何东西:

Array (
  [CONSUMER_KEY] => googlecodesamples.com
  [CONSUMER_SECRET] => [REQUEST_TOKEN] => [REQUEST_TOKEN_SECRET] => 
)

我在Google Oauth Reference

上找到了这个
  

如果您的申请未注册,请选择HMAC-SHA1并使用以下密钥和密码:
  消费者关键:“匿名”消费者   秘密:“匿名”

我更改了consumer_keyconsumer_secret变量,但返回的数组仍为空。

我不确定我做错了什么这是一个基本的H9沙箱开发程序;任何建议都会有所帮助。