xclib/php-yahoo-sdk

Yahoo! 社交 SDK - PHP5 库

v1.0.0 2020-08-28 06:51 UTC

This package is not auto-updated.

Last update: 2024-09-22 02:18:48 UTC


README

警告

yo-social-php5 SDK 已发布为 alpha 版本,且为实验性。yo-social-php5 sdk 和 yo-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附带示例代码,但您必须首先更新'examples/common.inc.php'文件,使用您的OAuth消费者密钥和密钥。

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