SpringPad API 的问题

发布于 2024-11-09 11:01:40 字数 1900 浏览 0 评论 0原文

我正在尝试使用 Springpad API 访问日期。

如果我使用以下链接:

http://springpadit.com/api/blocks/all?limit=1&text=HARRY+POTTER

我可以使用搜索词“JK Rowlings”获得 2 个最近的结果。

在授权我的服务器后,我编写了以下代码来执行相同的操作:

$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

我得到的只是一个空数组,我在这里做错了什么?

I'm trying to access date using the Springpad API.

If I use the following link:

http://springpadit.com/api/blocks/all?limit=1&text=HARRY+POTTER

I have no problem getting 2 recent results with the search term "J K Rowlings'.

I wrote the following code to do the same thing after authorizing my server:

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

This should let you create the same query and retrieve the data by using the following link:

http://xrefpro.com/CRM/index.php?query=HARRY+POTTER

All I get is an empty array for my results. What am I doing wrong here??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江挽川 2024-11-16 11:01:40

springpad api 调用“/api/blocks/all”是对所有用户公共数据的全局搜索。它不需要身份验证。 api 似乎确实存在一个错误,导致登录后搜索无法工作。您可以通过注销 springpad 并点击来测试这一点,

http://springpadit.com/api/blocks/all

然后在登录时尝试。

我想发生的是这样的情况尝试在您自己的帐户中找到包含该文本的块。我是 springpadit.com 的员工,我们将研究通过全局查询修复该错误。但现在,不要为全局查询而使用 oauth。

如果你想搜索你自己的帐户,请使用oauth并查询

http://springpadit.com/api/users/me/blocks?limit=1&text=Thor

响应不会有“块”节点,所以只需将打印更改为

print_r($json);

The springpad api call "/api/blocks/all" is a global search across all users public data. It does not require auth. There does seem to be a bug with the api that causes that search to not work if you are logged in. You can test this by logging out of springpad and hitting

http://springpadit.com/api/blocks/all

and then try it when logged in.

I imagine what is happening is it is trying to find a block with that text in your own account. I am an employee at springpadit.com, we will look into fixing that bug with global queries. For now though, don't bother with oauth for a global query.

If you want to search your own account, use oauth and query

http://springpadit.com/api/users/me/blocks?limit=1&text=Thor

The response won't have a "blocks" node, so just change the print to

print_r($json);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文