我對OAuth的概念相當陌生,我試圖與新的Rdio API交互。我已經設法使用PECL OAuth函數來驗證身份驗證,但是Rdio需要通過POST傳遞參數,並且我無法弄清楚這是如何完成的。身份驗證的工作原理:用戶退回到Rdio的網站並要求批准該應用程序,然後將其返回到該網站。然而,之後,調用API的請求失敗。使用PHP/PECL通過POST傳遞參數OAuth擴展
這裏的RDIO API的一些信息:http://developer.rdio.com/docs/REST/
這是我對驗證碼...斜體線是什麼,我相信應該在調用API請求方法命名爲「當前用戶」
$req_url = 'http://api.rdio.com/oauth/request_token';
$authurl = 'https://www.rdio.com/oauth/authorize';
$acc_url = 'http://api.rdio.com/oauth/access_token';
$callback = 'http://localhost/test.php';
$api_url = 'http://api.rdio.com/1';
$conskey = 'vmu7x6u4rk8vae8dn28h';
$conssec = 'GrY7gF';
session_start();
if(!isset($_GET['oauth_token']) && $_SESSION['state']==1) $_SESSION['state'] = 0;
try {
$oauth = new OAuth($conskey,$conssec,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_URI);
$oauth->enableDebug();
if(!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$request_token_info = $oauth->getRequestToken($req_url);
$_SESSION['secret'] = $request_token_info['oauth_token_secret'];
$_SESSION['state'] = 1;
header('Location: '.$authurl.'?oauth_token='.$request_token_info['oauth_token'].'&oauth_callback='.urlencode($callback));
exit;
} else if($_SESSION['state']==1) {
$oauth->setToken($_GET['oauth_token'],$_SESSION['secret']);
$access_token_info = $oauth->getAccessToken($acc_url);
$_SESSION['state'] = 2;
$_SESSION['token'] = $access_token_info['oauth_token'];
$_SESSION['secret'] = $access_token_info['oauth_token_secret'];
}
$args = "method=currentUser";
$oauth->setToken($_SESSION['token'],$_SESSION['secret']);
$oauth->fetch("$api_url", $args);
$json = json_decode($oauth->getLastResponse());
print_r($json);
} catch(OAuthException $E) {
print_r($E);
}
的消息,我回去:
Warning: OAuth::fetch(http://api.rdio.com/1?oauth_consumer_key=vmu7x6u4rktv468vae8dn28h&oauth_signature_method=HMAC-SHA1&oauth_nonce=12606272174d85622ad26ce8.80381248&oauth_timestamp=1300587050&oauth_version=1.0&oauth_token=238zec5p4rpcpbfd8j36sjggz3jfsssybhxgcn9kvmmrmdxr3t4f2cnspt4dg5xf&oauth_signature=1mZhJ9AUbi0sm6qhNaAntumAckU%3D) [function.OAuth-fetch]: failed to open stream: HTTP request failed! HTTP/1.0 596
問題是至多L可能的是參數(method = currentUser)不能通過POST正確傳遞。有沒有人有任何想法如何使用PECL的OAuth擴展來做到這一點?
$ callback ='http://localhost/test.php'; ?不應該是$ callback ='http://conectablehost.com/test.php'; – 2011-03-20 02:50:50
是的,我只是改變主機,以獲取我的代碼的細節。就像我在頂部使用假密鑰和密鑰一樣。 – 2011-03-20 04:02:16