oasis/php-yahoo-sdk

Yahoo! 社交 SDK - PHP5 库

v1.0.1 2017-05-27 06:10 UTC

This package is auto-updated.

Last update: 2024-09-04 17:57:51 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