1

我正在尝试获得三足 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_keyandconsumer_secret变量,但返回的数组仍然为空。

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

4

1 回答 1

0

嗯,我已经弄清楚了这一点,

当我打印 curl 的响应时,我收到一条消息:

此 URL 已移至此处:

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/饲料/

因此,一旦我将 $request_token_url 更改为此,它就像一种魅力,我终于有了一条腿!剩下两个:)

于 2010-08-25T22:08:47.470 回答