graphcomment / sdk-api-php
Graphcomment API 的 PHP 封装器
Requires
- php: >=5.5.0
- ext-json: *
- guzzlehttp/guzzle: ^6.3
README
#Graphcomment SDK API PHP 版本 2.3.2
使用 composer 安装
composer require graphcomment/sdk-api-php
-
封装器使用 Guzzle 的最新版本。
-
要使用 PHP 封装器,您必须在 Graphcomment.com 上创建账户并订阅付费计划。
使用此封装器,您将能够
- 当用户在您的网站上订阅时,自动在 GraphComment 上注册新用户。
- 当用户登录到您的网站时,将其连接到 GraphComment。
- 获取在 graphcomment 中保存的用户信息。
- 将用户信息从您的系统更新到 graphcomment。
- 获取线程上活跃评论的数量。
实现示例
$client = new Sdk(GC_PUBLIC_KEY, GC_SECRET_KEY);
在这些行之后,您可以调用函数。
- 注册用户
$client->registerUser('username', 'email', 'fr', 'https://graphcomment.com/image.jpg');
此函数返回一个包含其 "gc_id" 的 JSON 文件,您必须将其保存在数据库中以验证正在登录的用户,并保存 do_sync 同步日期。
- 登录用户,此函数返回 JWT 令牌 JSON,您必须将其保存在 localStorage 中以验证 Graphcomment。
$client->loginUser('gc_id');
要将 gc_token 保存在 localStorage 中,请在一个 0px 宽度的 iframe 中调用此 URL 以验证用户 => https://graphcomment.com/fr/auth.html?gc_token=[TOKEN-without-JWT-only-token]
要销毁 localStorage 会话,请在一个 0px 宽度的 iframe 中调用此 URL => https://graphcomment.com/fr/destroy.html
示例
连接
<iframe src="https://graphcomment.com/fr/auth.html?gc_token=eyJhbGciOiJIUzI1NiIsInR5cCI6kpXVCJ9.eyJfaWQiOiI1OGY5ZjQ5OTk3NzkwOTBkODYyMDgwOTIiLCJ1c2VybmFtZSI6ImRhdmlkIGRqaWFuIiwiZW1haWwiOiJzaXJiYWxkdXJAZ21haWwuY29tIiwiZmFjZWJvb2tfaWQiOiIxMDE1NDE3Mjk2NzQ1MTQ5MSIsImdvb2dsZV9pZCI6IjExNjEwMTAxNzgxODA3MjI5MDk0OCIsInJvbGUiOJ1c2VyIiwicGljdHVyZSI6Ii9pbWFnZXMvYXZhdGFyXzMucG5nIiwibGFuZ3VhZ2UiOiJmciIsImZyb21fd2Vic2l0ZSI6IjU4MWQyMTlmOGRmY2EwMzlhY2MMGZiZiIsInZhbGlkYXRpb24iOnt9LCJpYXQiOjE0OTk2ODYxMjIsImV4cCI6MTUwMjI3ODEyMn0.YyiANmL4-wzu1XGak1SbBmywZOWLHwjYsXtBW-Ikqx4 " frameborder="0" style="width:0px;height:0px;"></iframe>
断开连接
<iframe src="https://graphcomment.com/fr/destroy.html" frameborder="0" style="width:0px;height:0px;"></iframe>
- 获取最后一条用户信息
$client->getUser('gc_id');
获取用户信息,返回 JSON。
{
gc_id: 'gc_id',
username: 'username',
email: 'email@email.com',
language : 'en',
picture : 'https://graphcomment.com/image.jpg',
do_sync : date of synchronisation
}
- 在 Graphcomment 上更新用户
$client->updateUser('gc_id', 'username', 'email', 'fr', 'https://graphcomment.com/image.jpg');
返回 do_sync 日期和 gc_id,状态为 'updated'
- 计数线程评论
$client->countCommentscountComments('https://graphcomment.com/thread.html', 'content123');
- 导出评论以同步到您的数据库
此查询受每个查询 100 条评论的限制。
$client->exportComments();
以 json 数组形式列出 100 条评论
{
comments : [
{
"cached_author": {
"username": "gc",
"email": "grdnlndn@gmail.com"
},
"guest": false,
"status": "approved",
"spam": false,
"_id": "5cb0621843647e1332eba194",
"content": "test from GC 7",
"thread": {
"_id": "5c790ace3f227b1ac45a29b7",
"url": "http://localhost:8080/?p=5",
"page_title": "Article with GC",
"guid": "http://localhost:8080/?p=5",
"uid": "5"
},
"author": {
"profiles": [
{
"language": "fr",
"_id": "5c790acd3f227b1ac45a29b6",
"username": "gc",
"email": "grdnlndn@gmail.com",
"uid": "1"
}
],
"_id": "59c0cd87740e0704dba1cf6b"
},
"ip": "176.164.57.27",
"edited_at": "2019-04-12T10:02:00.376Z",
"created_at": "2019-04-12T10:02:00.343Z"
},
{
"cached_author": {
"username": "gc",
"email": "grdnlndn@gmail.com"
},
"guest": false,
"status": "deleted",
"spam": false,
"_id": "5cb0621843647e1332eba194",
"content": "test from GC 7",
"thread": {
"_id": "5c790ace3f227b1ac45a29b7",
"url": "http://localhost:8080/?p=5",
"page_title": "Article with GC",
"guid": "http://localhost:8080/?p=5",
"uid": "5"
},
"author": {
"profiles": [
{
"language": "fr",
"_id": "5c790acd3f227b1ac45a29b6",
"username": "gc",
"email": "grdnlndn@gmail.com",
"uid": "1"
}
],
"_id": "59c0cd87740e0704dba1cf6b"
},
"ip": "176.164.57.27",
"edited_at": "2019-04-12T10:02:00.376Z",
"created_at": "2019-04-12T10:02:00.343Z"
}
]
}
- 在您的系统中有效导入评论,发送确认
$client->exportConfirmComments([comment_id1, comment_id2, comment_id3...]);
此查询返回一个对象 JSON 数组
{
[
{_id : comment_id1, result: 'ok'},
{_id : comment_id2, result: 'ko', message:'comment id not found'},
{_id : comment_id3, result: 'ok'},
]
}
- 从 URL 和 Uid(可选)内容获取 JSON-LD 格式用于 SEO
$client->getThreadJsonLdFormat('https://graphcomment.com/thread.html', 'content123');
只有在我们数据库中存在评论升级错误时,消息才会存在。
评论导出返回已更改状态的评论,或在账户删除或正常编辑的情况下,用户已编辑的评论。您必须根据情况执行更新或插入函数。
因此,您可以创建一个作业以获取所有分钟并将 graphcomment 评论导入到您的数据库中。