我试图获得三条腿的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_key
和consumer_secret
变量,但返回的数组仍为空。
我不确定我做错了什么这是一个基本的H9沙箱开发程序;任何建议都会有所帮助。
答案 0 :(得分:0)
好吧,我已经把它想出来了,
当我打印出卷曲的反应时,我收到一条消息说:
此网址已移至此处:
所以,一旦我将$ request_token_url更改为此,它就像一个魅力,我终于有了一条腿!剩下两个:)