2011-02-08 40 views
1

我嘗試通過foursquare API獲取場地。我試過的步驟是:第一次用php設置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}")); 

我特別不明白回調的功能我在註冊中設立了。 謝謝!

回答

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。

1

回調URL是Foursquare在成功驗證Foursquare服務後引導用戶的地方。因此,如果您正在進行本地開發(例如使用WAMP + php),請將您的回撥地址設置爲http://localhost/YOUR_PAGE_NAME.php

那麼會發生什麼呢?

  • 有人訪問你的頁面
  • 你的頁面會提示他們有一個鏈接 指向四方(此鏈接中有你的應用程序的Client +祕密,讓四方知道這個用戶希望訂閱應用程序)
  • Foursqaure提示用戶登錄 和允許應用程序請求訪問
  • 四方重定向並傳遞一個令牌 回外部 應用程然後這個令牌可以是 用於所有後續請求 代表用戶

    我希望這有所幫助。

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

現在已經過時了。另外我在過去幾天發現Foursquare異步庫也爲我拋出錯誤,我不知道爲什麼。我已經在這裏張貼尋求幫助; http://groups.google.com/group/foursquare-api/browse_thread/thread/cd258a78d8073f86/ed5ff3f9fed206ed#ed5ff3f9fed206ed

安迪