OAuth 2.0 Client Library
, (*1)
This library makes it stupidly simple to integrate your application with OAuth 2.0 identity providers. It has built in support for:, (*2)
- Facebook
- Github
- Google
- Instagram
- LinkedIn
- Microsoft
- Vkontakte
- Kompas
Adding support for other providers is trivial., (*3)
The library requires PHP 5.3+ and is PSR-0 compatible., (*4)
First, you must install composer in your project., (*5)
Create a composer.json file in your project root:, (*6)
{
"require": {
"kompas/oauth2-client": "0.3"
}
}
Add this line to your applicationās index.php file:, (*7)
require 'vendor/autoload.php';
Usage for Kompas
// composer autoload
require_once "vendor/autoload.php";
$provider = new League\OAuth2\Client\Provider\Kompas(array(
'clientId' => 'XXXXXXXX',
'clientSecret' => 'XXXXXXXX',
'redirectUri' => ''
));
try {
// Try to get an access token (using the client credentials grant)
$t = $provider->getAccessToken('client_credentials');
try {
$provider->setFilterBySite('nasional,megapolitan');
$latest = $provider->getRssLatest($t);
$response['latestFiltered'] = json_decode($latest, true); // result filtered
$mostcommented = $provider->getRssMostCommented($t);
$response['mostCommentedFiltered'] = json_decode($mostcommented, true); // result filtered
$provider->setFilterBySite(); // reset filtered
$mostpopular = $provider->getRssMostPopular($t);
$response['mostPopularNonFiltered'] = json_decode($mostpopular, true); // result not filtered
} catch (Exception $e) {
// Failed to get Rss
$response = array(
'status' => false,
'error' => $e->getMessage()
);
}
} catch (Exception $e) {
// Failed to get access token
$response = array(
'status' => false,
'error' => $e->getMessage()
);
}
header("Content-Type: application/json");
echo json_encode($response);
Available Feature:, (*8)
getRssLatest(token, service, siteno, sectionid)
getRssMostCommented(token, service, siteno, sectionid)
getRssMostPopular(token, service, siteno, sectionid)
setFilterBySite(sites) *only in json format, (*9)
Example:, (*10)
$all_latest = $provider->getRssLatest(AccessToken);
$provider->setFilterBySite('nasional,megapolitan'); // (,) delimiter
$filter_latest = $provider->getRssLatest(AccessToken);
$provider->setFilterBySite(); // reset filter
$news_latest = $provider->getRssLatest(AccessToken, 'kompascom', 1, 1);
Kompas API Reference
Authorization:, (*11)
Request body
- HTTP request
POST http://apis.kompas.com/oauth2/token, (*12)
-
Parameters
Require body parameters, (*13)
- client_id [Your registered client id]
- client_secret [Your registered client secret]
- grant_type [MUST value "client_credentials"]
-
Example, (*14)
POST /oauth2/token HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
client_id=xxx&client_secret=xxx&grant_type=client_credentials
-
Response, (*15)
{
"access_token": "xxx",
"token_type": "bearer",
"expires": 1387445831,
"expires_in": 3600
}
Kompascom: latest
Requires authorization, (*16)
Request body
- HTTP request
GET http://apis.kompas.com/rss/kompascom/latest, (*17)
-
Parameters
Require query parameters, (*18)
- access_token [MUST value access token from authorization response]
Optional path parameters, (*19)
- siteId [integer]
- sectionId [integer]
Optional query parameters, (*20)
- filterBySite [string, delimeter with comma. ex: nasional,megapolitan]
-
Example all latests, (*21)
GET /rss/kompascom/latest?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example latest with filter sites, (*22)
GET /rss/kompascom/latest?access_token=xxx&filterBySite=nasional,megapolitan HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example latest for specific site, (*23)
GET /rss/kompascom/latest/1?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example latest for specific section site, (*24)
GET /rss/kompascom/latest/1/1?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Response, (*25)
[
{
uid: "2013.12.13.0711189",
channel: {
site: "bola",
section: ""
},
title: "Awal Januari, Trofi Piala Dunia Tiba di Indonesia",
description: "Coca-Cola sebagai official sponsor of the FIFA World Cup⢠...",
media: {
image: {
thumb: "http://assets.kompas.com/data/photo/2013/12/13/1458220455320155t.jpg",
content: "http://assets.kompas.com/data/photo/2013/12/13/1458220455320155780x390.jpg"
}
},
url: {
permalink: "http://bola.kompas.com/read/2013/12/13/0711189/Awal.Januari.Trofi.Piala.Dunia.Tiba.di.Indonesia"
},
service: "kompascom",
published_date: "2013-12-13 07:11:18"
},
...
]
Requires authorization, (*26)
Request body
- HTTP request
GET http://apis.kompas.com/rss/kompascom/mostcommented, (*27)
-
Parameters
Require query parameters, (*28)
- access_token [MUST value access token from authorization response]
Optional path parameters, (*29)
- siteId [integer]
- sectionId [integer]
Optional query parameters, (*30)
- filterBySite [string, delimeter with comma. ex: nasional,megapolitan]
-
Example all of most commented, (*31)
GET /rss/kompascom/mostcommented?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example most commented with filter sites, (*32)
GET /rss/kompascom/mostcommented?access_token=xxx&filterBySite=nasional,megapolitan HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example most commented for specific site, (*33)
GET /rss/kompascom/mostcommented/1?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example most commented for specific section site, (*34)
GET /rss/kompascom/mostcommented/1/1?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Response, (*35)
[
{
uid: "2013.12.13.0711189",
channel: {
site: "bola",
section: ""
},
title: "Awal Januari, Trofi Piala Dunia Tiba di Indonesia",
description: "Coca-Cola sebagai official sponsor of the FIFA World Cup⢠...",
media: {
image: {
thumb: "http://assets.kompas.com/data/photo/2013/12/13/1458220455320155t.jpg",
content: "http://assets.kompas.com/data/photo/2013/12/13/1458220455320155780x390.jpg"
}
},
url: {
permalink: "http://bola.kompas.com/read/2013/12/13/0711189/Awal.Januari.Trofi.Piala.Dunia.Tiba.di.Indonesia"
},
service: "kompascom",
published_date: "2013-12-13 07:11:18",
statistics: {
comment_count: 279
}
},
...
]
Kompascom: Most Popular
Requires authorization, (*36)
Request body
- HTTP request
GET http://apis.kompas.com/rss/kompascom/mostpopular, (*37)
-
Parameters
Require query parameters, (*38)
- access_token [MUST value access token from authorization response]
Optional path parameters, (*39)
- siteId [integer]
- sectionId [integer]
Optional query parameters, (*40)
- filterBySite [string, delimeter with comma. ex: nasional,megapolitan]
-
Example all of most popular, (*41)
GET /rss/kompascom/mostpopular?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example most popular with filter sites, (*42)
GET /rss/kompascom/mostpopular?access_token=xxx&filterBySite=nasional,megapolitan HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example most popular for specific site, (*43)
GET /rss/kompascom/mostpopular/1?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Example most popular for specific section site, (*44)
GET /rss/kompascom/mostpopular/1/1?access_token=xxx HTTP/1.1
Host: apis.kompas.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
-
Response, (*45)
[
{
uid: "2013.12.13.0711189",
channel: {
site: "bola",
section: ""
},
title: "Awal Januari, Trofi Piala Dunia Tiba di Indonesia",
description: "Coca-Cola sebagai official sponsor of the FIFA World Cup⢠...",
media: {
image: {
thumb: "http://assets.kompas.com/data/photo/2013/12/13/1458220455320155t.jpg",
content: "http://assets.kompas.com/data/photo/2013/12/13/1458220455320155780x390.jpg"
}
},
url: {
permalink: "http://bola.kompas.com/read/2013/12/13/0711189/Awal.Januari.Trofi.Piala.Dunia.Tiba.di.Indonesia"
},
service: "kompascom",
published_date: "2013-12-13 07:11:18",
statistics: {
read_count: 279
}
},
...
]
License
The MIT License (MIT). Please see License File for more information., (*46)