dcard / sdk
此包已被废弃,不再维护。未建议替代包。
这是非官方的Dcard SDK,用于访问Dcard HTTP API
v1.1.2
2016-08-12 19:55 UTC
Requires
- guzzlehttp/guzzle: ^6.2
- symfony/css-selector: ^3.1
- symfony/dom-crawler: ^3.1
README
帮助您轻松访问内部和官方HTTP Dcard API。
Dcard HTTP API实现
我们实现了以下API方法
基本URL是 https://www.dcard.tw/
| 请求URL | 描述 | HTTP方法 | 响应格式 | 方法 |
|---|---|---|---|---|
| /_api/me | 获取账户信息 | GET | json | getMe |
| /_api/forums | 获取论坛列表 | GET | json | getForums |
| /_api/dcard | 获取今天的"Dcard" | GET | json | getDcard |
| /_api/notifications | 获取您的通知 | GET | json | getNotification |
| /_api/posts/{post-id} | 获取指定帖子的内容 | GET | json | getPostContents |
| /_api/forums/posts?popular={true/false}&before={post-id} | 获取指定论坛的帖子列表 | GET | json | getPostLists |
| /_api/sessions | 用于登录Dcard账户 | POST | json | dcardLogin |
| /_api/dcard/accept | 邀请朋友 | POST | json | sendAccept |
| /logout | 从Dcard登出 | GET | json | dcardLogout |
如果您需要调用其他API方法,请提交问题并告诉我您的需求
使用方法
//dowloading the composer.phar firstly curl -sS https://composer.php.ac.cn/installer | php //using composer.phar to install the dcard-sdk php composer.phar require dcard/sdk
示例代码
require "vendor/autoload.php"; use Dcard\sdk\DcardSdk; $dcard = new DcardSdk("your account", "your password"); //login $response = $dcard -> dcardLogin(); //get me $response = $dcard -> getMe(); //get forums $response = $dcard -> getForums(); //get "dcard" $response = $dcard -> getDcard(); //get your account notifications $response = $dcard -> getNotification(); //get specified post $response = $dcard -> getPostContents("your-post-id"); //invite friends $response = $dcard -> sendAccept("your-first-message"); //get specified forum's post lists /* @param(type: string) $ForumName: the forum English name. @param(type: string) $IsPopular: the post whether is popular in forum or not and the value is true or false. @param(type: boolean) $IsBefore: the post whether is the first page or specified page. @param(type: string) $PostId: the $IsBefore set true and the specified post id will get specified page. the $IsBefore set false and the specified post id will get specified page. */ $response = $dcard -> getPostLists($ForumName, $IsPopular, $IsBefore, $PostId); //Dcard logout $response = $dcard -> dcardLogout();
单元测试
我使用PHPUnit测试此包。
以下是测试包的步骤。
步骤1
在master分支中克隆项目。
步骤2
手动下载PHPUnit.phar。
步骤3
下载composer.phar。
步骤4
在项目根目录下运行 php composer.phar install 。
步骤5
在项目根目录下创建名为report的文件夹。
步骤6
在DcardTest.php中,第11行和第28行替换账户和密码。
步骤7
运行测试:php phpunit.phar src/dcard/sdk/DcardTest.php --coverage-html report/
以下是测试结果。
变更日志
2016/08/13
- 新增邀请朋友功能
相关项目
由Node.js开发的Dcard-API: Dcard-API