开发者

OAuth H9 Google Health

I am attempting to gain three-legged Oauth access, but I can't get the first step to work. My code so far:

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);

I'm using OAuth.php.

The returning array does not give me anyth开发者_StackOverflowing:

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

I found this on the Google Oauth Reference

If your application is not registered, select HMAC-SHA1 and use the following key and secret:

consumer key: "anonymous" consumer

secret: "anonymous"

I have altered the consumer_key and consumer_secret variables but the returning array remains empty.

I'm not sure what I'm doing wrong this is a basic H9 sandbox development procedure; any advice would help.


Well I have figured this one out,

When I printed the response of the curl I got a message which said:

This URL has moved here:

https://www.google.com/accounts/OAuthGetRequestToken?oauth_consumer_key=anonymous%20%20%20%20[amp;oauth_nonce]%20=%3E%20828f80d4cec64b5b6fcca5010e2aa952%20%20%20%20[amp;oauth_signature]%20=%3E%20H+WrK1WIhyFEkrHRBvjpzcVLFvs=%20%20%20%20[amp;oauth_signature_method]%20=%3E%20HMAC-SHA1%20%20%20%20[amp;oauth_timestamp]%20=%3E%201282773417%20%20%20%20[amp;oauth_version]%20=%3E%201.0%20%20%20%20[amp;scope]%20=%3E%20https://www.google.com/h9/feeds/

So once I changed the $request_token_url to this, it worked like a charm and I finally have one-leg!! two left :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜