cerbero/yos-social-php5

Yahoo! 社交 SDK - PHP5 库

dev-master 2014-09-04 09:43 UTC

This package is auto-updated.

Last update: 2024-09-04 22:51:16 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

托管在 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 文件

安装

下载并解压缩发布包后,将 '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