没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
oss.trustie.net/open_source_projects | 主页 > 开源项目社区 > douban-api-examples |
douban-api-examples
|
0 | 0 | 0 |
贡献者 | 讨论 | 代码提交 |
Examples of douban-api
douban-api运行环境搭建及douban-api安装,请参考douban-api-installation
Examples of douban-php-client1,请先申请API_KEY,得到API_KEY和私钥。
2,API认证授权。豆瓣API认证通过以下三个步骤完成:
a). 获取未授权的 Request Token
b). 请求用户授权 Request Token
c). 使用授权后的 Request Token 换取 Access Token
Zend_Gdata_DouBan的方法programmaticLogin完成了上述过程,详细过程请参考代码。
下列命令生成了一个Zend_Gdata_DouBan对象,并完成了豆瓣API认证过程:
$client = new Zend_Gdata_DouBan($api, $secret);
$client->programmaticLogin();运行上述代码时,输出如下提示信息:
please paste the url in your webbrowser, complete the authorization then come back:
http://www.douban.com/service/auth/authorize?oauth_token=5d6f7b964ef6f60c184e72c2ece4e224
将上述url连接拷贝到浏览器,进入到douban api认证授权页面,点击同意,即可完成对本次api访问的授权。
3,正常的douban api操作。完成上述认证过程,即可使用Zend_Gdata_DouBan所提供各种接口进行操作,下面例举了几个简单应用:
$peopleEntry = $client->getPeople('ahbei');
assert ($peopleEntry->getId() 'http://api.douban.com/people/1000001');
assert ($peopleEntry->getLocation()->getText() '北京');
assert ($peopleEntry->getTitle()->getText() == '阿北');
$peopleFeed = $this->_client->searchPeople('boy', 2, 10);
$arr = $peopleFeed->getEntry();
$arr_title = array();
foreach ($arr as $entry) {
if ($entry->getTitle()) {
$arr_title[$entry->getTitle()->getText()] = 1;
}
}
assert (array_key_exists('cow-boy', $arr_title));
$peopleEntry = $client->getAuthorizedUid();
assert ($peopleEntry->getUid()->getText() == "2463802");
$peopleFeed = $this->_client->GetFriends("2463802");
$arr = $peopleFeed->getEntry();
$uid_arr = array();
foreach ($arr as $entry) {
if ($entry->getUid()) {
$uid_arr[$entry->getUid()->getText()] = 1;
}
}
assert (array_key_exists("jili8", $uid_arr));更多使用示例,请参考test_douban.php
Examples of douban-python-client1,请先申请API_KEY,得到API_KEY和私钥。
2,如下命令完成了API认证过程:
client = douban.service.DoubanService(server=SERVER, api_key=API_KEY,secret=SECRET)
client.ProgrammaticLogin(token_key=TOKEN_KEY,token_secret=TOKEN_SECRET)运行上述代码时,输出如下提示信息:
please paste the url in your webbrowser, complete the authorization then come back:
http://www.douban.com/service/auth/authorize?oauth_token=5d6f7b964ef6f60c184e72c2ece4e224
将上述url连接拷贝到浏览器,进入到douban api认证授权页面,点击同意,即可完成对本次api访问的授权。
3,正常的api操作。下面例举了几个简单的应用:
people = client.GetPeople('/people/1000001')
assert people.uid.text 'ahbei'
assert people.title.text "阿北"
assert people.location.text == "北京"
feed = client.SearchPeople("阿北")
assert any( e.title.text == "阿北" for e in feed.entry)
people = client.GetAuthorizedUID('/people/@me')
assert people.uid.text == '2463802'更多示例,请参考test_service.py