1
我想使用Springpad API訪問日期。與SpringPad API的問題
如果我使用下面的鏈接:
http://springpadit.com/api/blocks/all?limit=1&text=HARRY+POTTER
我沒有問題,取得最近2個結果與搜索詞「JK Rowlings'
我寫了下面的代碼做同樣的事情後,授權我的服務器:
$api_url = "http://springpadit.com/api/";
$query = $_GET['query'];
$param = array('limit'=>1, 'text'=>$query);
$temp = http_build_query($param,"","&");
$url = $api_url."blocks/all?".$temp;
session_start();
// In state=1 the next request should include an oauth_token.
// If it doesn't go back to 0
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_token_secret='.$_SESSION['secret']);
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'];
}
$oauth->setToken($_SESSION['token'],$_SESSION['secret']);
$oauth->fetch($url);
$json = json_decode($oauth->getLastResponse(),true);
print_r($json['blocks']);
} catch(OAuthException $E) {
print_r($E);
}
這應該讓你創建相同的查詢和檢索使用下面的鏈接數據:
http://xrefpro.com/CRM/index.php?query=HARRY+POTTER
我得到的所有數據都是我的結果的空數組。我在這裏做錯了什麼?
是什麼的var_dump($ oauth-> getLastResponse()獲得);給你? – 2011-05-25 20:46:21
@ kyle-hudson它給了我 字符串(15)「{」blocks「:[]}」 – 2011-05-25 21:00:40
好吧,這表明沒有任何東西從springpadit返回。 – 2011-05-25 21:03:18