roroxide / yos-social-php5
Yahoo! 社交 SDK - PHP5 库
Requires
- php: >=5.5.9
- laravel/framework: ~5.2
This package is not auto-updated.
Last update: 2024-09-14 19:09:29 UTC
README
警告
yos-social-php5 SDK 以 alpha 版本发布,属于实验性。与 yos-social-php SDK 的区别在于存储由用户自行实现。新的实现更加灵活,开发者可以将 OAuth 令牌存储在 PHP 会话、数据库或 memcache 中。除非合作伙伴有需求,否则无需 PHP 会话。这意味着没有与 'hasSession' 或 'requireSession' 等效的方法。此功能的一个实现示例可以在 yos-social-php5/examples/simpleauth/simpleauth.php 中找到。
在 Yahoo! 开发者网络中查找文档和支持: http://developer.yahoo.com
- Yahoo! 应用平台 - http://developer.yahoo.com/yap/
- Yahoo! 社交 API - http://developer.yahoo.com/social/
- Yahoo! 查询语言 - http://developer.yahoo.com/yql/
托管于 GitHub: http://github.com/yahoo/yos-social-php5/tree/master
许可
@版权:Yahoo! Inc. 编写的代码的版权受以下条款许可:@许可:BSD 开源许可
Yahoo! 社交 SDK 软件许可协议(BSD 许可)版权所有(c)2009,Yahoo! Inc. 保留所有权利。
只要满足以下条件,允许以源代码和二进制形式重新分发和使用本软件,无论是否修改:
-
源代码重新分发必须保留上述版权声明、本条款列表和以下免责声明。
-
二进制形式的重新分发必须在文档和/或其他与分发提供的材料中重新生产上述版权声明、本条款列表和以下免责声明。
-
未经 Yahoo! Inc. 的具体预先书面许可,不得使用 Yahoo! Inc. 的名称或其贡献者的名称来认可或推广源自本软件的产品。
本软件由版权所有者和贡献者提供“按原样”且不提供任何明示或暗示的保证,包括但不限于对适销性和针对特定目的的适用性的暗示保证。在任何情况下,版权所有者或贡献者均不对任何直接、间接、偶然、特殊、示范性或后果性损害(包括但不限于替代商品或服务的采购;使用、数据或利润的损失;或业务中断)承担责任,无论该损害是否因使用本软件引起,即使已告知此类损害的可能性。
Yahoo! 社交 PHP SDK 代码受 BSD 许可证约束,请参阅 LICENSE 文件。
需求
以下依赖项与 Yahoo! PHP SDK 一起捆绑,但受单独许可协议约束。有关更多信息,请参阅捆绑的 LICENSE 文件。
- OAuth - http://code.google.com/p/oauth
- OpenID - http://www.openidenabled.com/php-openid/
- OpenSocial - http://code.google.com/p/opensocial-php-client/
- JSON - http://pear.php.net/Services_JSON
安装
下载并解压缩发布版后,将 'lib' 目录的内容复制到可以通过 PHP include_path 方法访问的目录中。
示例
SDK 包含示例代码,但您必须首先使用 OAuth 客户端密钥和密钥更新 'examples/common.inc.php' 文件。
define('OAUTH_CONSUMER_KEY', '###');
define('OAUTH_CONSUMER_SECRET', '###');
define('OAUTH_DOMAIN', '###');
define('OAUTH_APP_ID', '###');
在 Yahoo! 开发者仪表板中创建 OAuth 应用程序
http://developer.yahoo.com/dashboard/
获取 YQL
请参阅 examples/yql/delicious.php 中打包的示例代码。
$yql = new YahooYQLQuery();
$response = $yql->execute('select * from delicious.feeds.popular');
if(isset($response->query) && isset($response->query->results))
{
var_dump($response->query->results);
}
elseif(isset($response->error))
{
print sprintf('YQL query failed with error: "%s".', $response->error->description);
}
else
{
print 'YQL response malformed.';
}
获取社交数据
# Yahoo! OAuth Credentials - http://developer.yahoo.com/dashboard/
$CONSUMER_KEY = '##';
$CONSUMER_SECRET = '##';
$APPLICATION_ID = '##';
$CALLBACK_URL = '##';
$oauthapp = new YahooOAuthApplication($CONSUMER_KEY, $CONSUMER_SECRET, $APPLICATION_ID, $CALLBACK_URL);
# Fetch request token
$request_token = $oauthapp->getRequestToken($CALLBACK_URL);
# Redirect user to authorization url
$redirect_url = $oauthapp->getAuthorizationUrl($request_token);
# Exchange request token for authorized access token
$access_token = $oauthapp->getAccessToken($request_token, $_REQUEST['oauth_verifier']);
# update access token
$oauthapp->token = $access_token;
# fetch user profile
$profile = $oauthapp->getProfile();
var_dump($profile);
插入更新
$oauthapp->insertUpdate(array(
'title' => "cloned the yos-social-php5 SDK on Github",
'description' => "A PHP5 SDK for YQL",
'link' => "http://github.com/yahoo/yos-social-php5",
'imgURL' => 'http://github.com/images/modules/header/logov3.png',
'imgWidth' => '100',
'imgHeight' => '45'
));
使用 SimpleAuth(OpenID + OAuth)进行签名
See the bundled sample code in examples/simpleauth/simpleauth.php.
使用 OpenSocial 获取人员和活动
See the bundled sample code in examples/opensocial/profile.php.
添加联系人
# valid 'Yahoo! Contacts Read/Write' scopes are required to support this method.
$contact_fields = array();
$contact_fields[] = array('type' => 'email', 'value' => 'me@domain.com');
$contact_fields[] = array('type' => 'name', 'value' => array('givenName'=> 'John', 'familyName' => 'Doe'));
$contact = array('fields' => $contact_fields);
var_dump($oauthapp->addContact($contact));
测试
Yahoo! PHP SDK 包含用于验证功能的测试套件。测试还显示了功能示例和结果。要运行测试套件,只需执行测试套件即可
php phpunit test/AllTests.php