1

我尝试通过foursquare api获取场地。我尝试的步骤是:

  • 注册了我的应用程序;
  • 获取access_token;
  • 下载foursquare-aync库

这是我尝试使用但没有用的代码:

require_once("Api_Foursquare_EpiCurl");
require_once("Api_Foursquare_EpiFoursquare");
require_once("Api_Foursquare_EpiSequence");

$fsObj = new EpiFoursquare($clientId, $clientSecret, $accessToken);
$venue = $fsObj->get('/venues/search', array('ll' => "{$myLat},{$myLng}"));

特别是我不了解我在注册中设置的回调的功能。谢谢!

4

2 回答 2

1

回调 URL 是 Foursquare 在用户成功通过 Foursquare 服务进行身份验证后引导用户的位置。因此,如果您正在进行本地开发(例如使用 WAMP + php),请将您的回调地址设置为http://localhost/YOUR_PAGE_NAME.php

所以会发生的是这样的;

  • 有人访问您的页面
  • 您的页面使用指向 Foursquare 的链接提示他们(此链接中包含您的应用程序的 clientId + 密码,让foursquare 知道该用户希望订阅您的应用程序)
  • Foursqaure 提示用户登录并允许应用程序请求访问
  • Foursquare 重定向并将令牌传递回外部应用程序,然后此令牌可以代表用户用于所有后续请求

    我希望这会有所帮助。

虽然我注意到您可能正在使用本教程 - http://www.joesiewert.com/2010/04/how-to-use-the-foursquare-api-with-oauth-and-php/

现在已经过时了。此外,在过去的几天里,我还发现 Foursquare-async 库也在为我抛出错误,我不知道为什么。我在这里发帖寻求帮助; http://groups.google.com/group/foursquare-api/browse_thread/thread/cd258a78d8073f86/ed5ff3f9fed206ed#ed5ff3f9fed206ed

安迪

于 2011-02-15T10:28:51.020 回答
1

我得到了它的工作:

$consumer_key = 'YOURS';
$consumer_secret = 'YOURS';

//Includes the foursquare-asyc library files                                                                       
require_once('EpiCurl.php');
require_once('EpiSequence.php');
require_once('EpiFoursquare.php');

try{
  $foursquareObj = new EpiFoursquare($consumer_key, $consumer_secret);
  $venue = $foursquareObj->get('/venues/search',array('ll'=>'{your-lat},{your-long}'));
  var_dump($venue);
} catch (Execption $e) {
  //If there is a problem throw an exception                                                                       
}

从 4Square 转储出预期的 loc 数据。

我使用的是 2011 年 1 月 6 日版本的 EpiCurl、EpiSequence 和 2011 年 2 月 25 日版本的 EpiFoursquare。

于 2011-05-09T18:12:13.313 回答