Yahoo api bbauth:src或appid无效(缺失)

时间:2013-01-06 14:53:05

标签: php authentication yahoo

我正在尝试加载雅虎用户的电子邮件(但我坚持使用auth步骤):

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>';

但它不会创建链接或显示错误(脚本死亡)。

2 个答案:

答案 0 :(得分:1)

由于您使用的是基于浏览器的身份验证,因此您需要确保注册应用程序。您需要从https://developer.apps.yahoo.com/wsregapp/获取您的应用程序ID和密码。这与您创建OAuth项目的位置不同。 BBAuth只有应用程序ID和秘密。

在您的情况下,似乎问题是您的应用程序ID无效。考虑到其他答案和讨论,您似乎已经创建了OAuth项目而不是基于浏览器的身份验证项目。

关于你的问题“我应该将'some_aplication_data'替换为其他东西吗?”。根据文档,您可能希望用session_id()替换'some_aplication_data'。

修改

我已使用上述建议测试了您的代码,并且它运行正常。

答案 1 :(得分:0)

您可以通过这种方式生成身份验证网址

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

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

相关问题