我正在尝试加载雅虎用户的电子邮件(但我卡在了授权步骤):
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;
}
但是我在 yahoo 登录页面中得到这个错误:
Invalid (missing) src or 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>';
但它不会创建链接或显示错误(脚本死掉)。
最佳答案
由于您正在使用基于浏览器的身份验证,因此您需要确保您正在注册您的应用程序。您需要从 https://developer.apps.yahoo.com/wsregapp/ 获取您的应用程序 ID 和密码.这与您创建 OAuth 项目的位置不同。 BBAuth 只有应用程序 ID 和密码。
在您的情况下,问题似乎是您的应用程序 ID 无效。考虑到其他答案和讨论,您似乎创建了一个 OAuth 项目而不是一个基于浏览器的身份验证项目。
关于您的问题“我应该用其他东西替换‘some_aplication_data’吗?”。根据文档,您可能希望将“some_aplication_data”替换为 session_id()。
编辑
我已经按照上述建议测试了您的代码,它运行正常。
关于php - 雅虎 API bbauth : Invalid (missing) src or appid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14183277/