2013-01-06 36 views
3

我試圖加載雅虎用戶的電子郵件(但我卡上的身份驗證步驟):雅虎API bbauth:無效(丟失)SRC或APPID

define("APPID", 'dj***NQ--'); 
define("SECRET", '3***7'); 

// Include the proper class file 
$v = phpversion(); 

if ($v[0] == '4') { 
    include("includes/yahoo/ybrowserauth.class.php4"); 
} elseif ($v[0] == '5') { 
    include("includes/yahoo/ybrowserauth.class.php5"); 

} else { 
    die('Error: could not find the bbauth PHP class file.'); 
} 
$authObj = new YBBauthREST(APPID, SECRET); 
//echo APPID; 
// If Yahoo! isn't sending the token, then we aren't coming back from an 
// authentication attempt 
if (empty($_GET["token"])) { 
    // You can send some data along with the authentication request 
    // In this case, the data is the string 'some_application_data' 
    echo 'You have not signed on using BBauth yet<br /><br />'; 
    echo '<a href="'.$authObj->getAuthURL('some_application_data', true).'">Click here to authorize</a>'; 
    return; 
} 

但我在得到這個錯誤雅虎登錄頁面:

無效(丟失)SRC或APPID

所以我猜這裏是什麼問題?

echo '<a href="'.$authObj->getAuthURL('some_application_data', true).'">Click here to authorize</a>'; 

我應該用別的東西替換'some_aplication_data'嗎?

編輯:

我也試過:

$callback = YahooUtil::current_url()."?in_popup"; 
$auth_url = YahooSession::createAuthorizationUrl(APPID, SECRET, $callback); 
echo '<a href="'.$auth_url.'">Click here to authorize</a>'; 

但它不會創建鏈接或顯示錯誤(腳本死亡)。

+0

如果腳本死亡,使在PHP錯誤日誌記錄和跟蹤錯誤日誌。另外,您的其他錯誤消息顯示,您不會在意*發生的位置,因爲信息已從中刪除,只有模糊的代碼位置跟隨而不是提供報告的位置。改善故障排除的空間很大,我建議你這樣做。 – hakre

回答

0

您可以用這種方法生成的驗證網址

$callback = YahooUtil::current_url()."?in_popup"; 
$auth_url = YahooSession::createAuthorizationUrl(CONSUMER_KEY, CONSUMER_SECRET, $callback); 

參考 http://developer.yahoo.com/oauth/guide/oauth-userauth.html

+0

這對我來說不起作用(或者顯示錯誤) –

+0

爲什麼不能做這項工作? – cjds

+0

腳本crahes不用其他顯示錯誤,所以我不知道爲什麼...編輯我的問題與我試過 –

1

由於您使用的基於瀏覽器的認證,那麼你需要確保你正在註冊您的應用程序這樣。您需要從https://developer.apps.yahoo.com/wsregapp/獲取您的申請ID和密碼。這與您要創建OAuth項目的位置不同。 BBAuth只有應用程序ID和密碼。

對你來說,這似乎是問題是,你有一個無效的應用程序ID。考慮到其他答案和討論,看起來您已經創建了一個OAuth項目,而不是基於瀏覽器的身份驗證項目。

關於你的問題:「我應該取代‘some_aplication_data’白衣別的東西?」。根據文檔,你可能想用session_id()替換'some_aplication_data'。

編輯

我已經測試你的代碼與上述建議,並能正常工作。

+0

嗨!感謝您的回覆,我得到了這個其他關鍵/保密和授權作品(這一步,不是下一個......但我會打開另一個問題) –