tonoman3g/kaskus-php-sdk

关于此包最新版本(v0.2.0)没有可用的许可信息。

Kaskus SDK for PHP

v0.2.0 2015-07-14 07:56 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:26:46 UTC


README

此仓库包含一个开源PHP SDK,允许您从PHP应用程序中访问Kaskus API。

此版本的Kaskus SDK for PHP需要:

  • PHP 5.4或更高版本。
  • Composer

安装

  1. 在您的composer.json中需要此库
{
  "require": {
    "tonoman3g/kaskus-php-sdk": "v0.2.0"
  }
}
  1. Composer 是使用Kaskus SDK for PHP的先决条件。

全局安装composer,然后运行 composer install 以安装所需文件。

  1. 获取您应用程序的消费者密钥和消费者密钥。

  2. 在您的应用程序中需要 vendor/autoload.php

  3. 按照示例脚本进行进一步使用

用法

最小示例

<?php

// skip these two lines if you use composer 
define('KASKUS_SDK_SRC_DIR', '/path/to/kaskus-sdk-for-php/src/Kaskus/');
require __DIR__ . '/path/to/kaskus-sdk-for-php/autoload.php';

// skip this line if you do not use composer
require 'vendor/autoload.php';

$consumerKey = 'YOUR_API_KEY';
$consumerSecret = 'YOUR_API_SECRET';

$client = new \Kaskus\KaskusClient($consumerKey, $consumerSecret);

try {
    $response = $client->get('v1/hot_threads');
    $forumList = $response->json();
    print_r($forumList);
} catch (\Kaskus\Exceptions\KaskusRequestException $exception) {
    // Kaskus Api returned an error
    
} catch (\Exception $exception) {
    // some other error occured
    
}

使用Kaskus登录

使用此 Oauth示例

高级用法

我们使用guzzle作为HTTP客户端,关于进一步使用,请参阅 Guzzle

API文档

GET /v1/hot_threads

获取所有当前热门帖子

GET /v1/thread/<thread_id>?field=thread,thread_id,total_post,current_page,per_page,open,total_page,posts,profilepicture,post_username,post_userid,title,decoded,dateline,profilepicture,usertitle,post_id,reputation_box,pagetext,enable_reputation&page=1&limit=20

Parameter:
thread_id : thread id to read
field : fields name separated by comma that we want to filter from response
page : page that we want to read
limit : post per page that we want to read

获取特定帖子ID的帖子详情