3xw / cakephp-social
该软件包最新版本(3.4.1.2)没有提供许可证信息。
CakePHP 社交解析器
3.4.1.2
2018-02-12 16:03 UTC
Requires
- php: >=5.6
- cakephp/cakephp: ^3.4
- facebook/graph-sdk: ^5.6
- friendsofcake/search: ^3.2
- j7mbo/twitter-api-php: ^1.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-16 19:25:59 UTC
README
将社交网络引入您的网站
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 软件包的推荐方法是
composer require 3xw/cakephp-social
在 config/boostrap.php 中加载它
Plugin::load('Trois/Social', ['routes' => true]);
在数据库设置中,允许 app.php 中的正确 utf8
...
Datasources => [
'default' => [
...
'encoding' => 'utf8mb4',
...
]
],
...
'Social' => [
'facebook' => [
'app_id' => 'XXX',
'app_secret' => 'XXX',
'default_graph_version' => 'v2.11',
],
'twitter' => [
'oauth_access_token' => 'XXX',
'oauth_access_token_secret' => 'XXX',
'consumer_key' => 'XXX',
'consumer_secret' => 'XXX'
],
],
...
dB
创建一个名为 db 的表来存储帖子,如果您使用插件表类,建议以下内容:
CREATE TABLE `social_posts` (
`id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`provider` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'facebook',
`date` datetime NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`display` tinyint(1) NOT NULL DEFAULT '1',
`link` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`message` text COLLATE utf8mb4_unicode_ci,
`author` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`image` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`,`provider`),
KEY `provider` (`provider`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
用法
Shell
bin/cake social [facebook | instagram | twitter] [account | search] [needle] [limit] [-s] [-m table class]
代码
您有三个类(Facebook、Instagram、Twitter)实现了
public $posts = [];
public function query($type, $key, $limit = 10);
public function toArray();
您可以这样使用它
use Trois\Social\Network\Http\Facebook;
$this->Facebook = new Facebook();
$this->Facebook->query('account, 'xxxxyyyy', 10); // searchType, needle, limit
debug($Facebook->toArray());
您还有一个模型
use Cake\ORM\TableRegistry;
$this->SocialPosts = TableRegistry::get('Trois/Social.SocialPosts');
$entities = $this->SocialPosts->newEntities($this->Facebook->toArray());
$results = $this->SocialPosts->saveMany($entities);
管理界面
如果您有管理界面,您可以访问
/admin/social
并管理 'Trois/Social.SocialPosts' 表的内容