定制 akkaweb/cakephp-facebook 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

akkaweb/cakephp-facebook

Composer 安装命令:

composer require akkaweb/cakephp-facebook

包简介

CakePHP 3 Facebook Plugin

README 文档

README

IMPORTANT: SUPPORT FOR THIS BRANCH HAS BEEN DISCONTINUED. Use SDK5 Branch or latest tagged version. This branch (Master) will be kept to support Facebook SDKv4 but will not continue to be improved. I am currently working on supporting Facebook SDKv5. Follow installation instructions in that branch.

CakePHP 3 Facebook Plugin

A CakePHP 3.x Plugin to allow Facebook Login into an application.

Total Downloads License Gitter

Requirements

  • CakePHP 3.x with Auth component correctly setup. Refer to http://book.cakephp.org/3.0/en/controllers/components/authentication.html for setup
  • PHP 5.4.6+
  • Facebook PHP SDK 4.0+
  • Users Table with at least the following columns
    • facebook_id varchar(20)
    • first_name // can be set in config
    • last_name // can be set in config
    • username // can be set in config
    • password // can be set in config

For existing applications that already have a first_name, last_name, username and password already created with a different column name, you can dynamically set it in configuration options when loading the Component to your AppController.php file. See section 2 of Configuration below

NOTE: Facebook PHP SDK is a requirement. Composer will automatically install Facebook for you if not already installed. If manual download is chosen, you must download the Facebook Source into vendor/facebook/php-sdk-v4 and make sure it can be loaded by the composer. Else you need to manually include FAcebook's autoload.php file in your application's bootstrap.php.

Included

  • Facebook Graph Component
  • Facebook Graph Helper
    • $this->Facebook->loginLink()
    • $this->Facebook->likeButton()
    • $this->Facebook->shareButton()
    • $this->Facebook->sendButton()
    • $this->Facebook->followButton()
    • $this->Facebook->comments()
    • $this->Facebook->embeddedPosts()
    • $this->Facebook->embeddedVideo()
    • $this->Facebook->page()

***** See below for more details on how to use each

Installation

Composer (Best Choice)
  1. Add the following to your composer.json located in the root of your application, in the require section . ie. /var/www/domain.com/composer.json
// NOTE: Use instructions in SDK5 Branch if this is a new installation. This branch his no longer supported.

"require": {
	"akkaweb/cakephp-facebook": "dev-master"
}
  1. Run the following at the root of your application
sudo php composer.phar update

Note: if composer.phar is not found, you need to install it. Follow CakePHP's documentation here -> http://book.cakephp.org/3.0/en/installation.html. Refer to Installing Cakephp section

Git Clone (plugins/AkkaFacebook)

git clone git@github.com:akkaweb/AKKA-CakePHP-Facebook-Plugin.git

Download

https://github.com/akkaweb/AKKA-CakePHP-Facebook-Plugin/archive/master.zip

Note: When installing with either manual download or Git Clone and CakePHP complains it cannot find the plugin, you need to add the plugin to vendor/cakephp-plugins.php in the plugins array [] --> 'AkkaFacebook' => $baseDir . '/plugins/AkkaFacebook/'. If you are using composer, running php composer.phar dumpautoload could be sufficient. If it does not work add the following to the "autoload" section in the root application's composer.json file in the "psr-4": section: "AkkaFacebook\\": "./plugins/AkkaFacebook/src"

Configuration

  1. Load the plugin in your application's bootstrap.php file:
Plugin::load('AkkaFacebook', ['bootstrap' => false, 'routes' => true]);
  1. Load the plugin's component in AppController.php

Note: You need to obtain your facebook App Id and App Secret from http://developers.facebook.com. Once you are on that page and have an App created, you can retrieve your App Id and App Secret. Make sure you add your domain to App Domains in the Settings page.

user_columns is optional and should only be used if your Users database columns defer from the defaults as specified in the Requirement section, above.

public function initialize(){
    parent::initialize();
    
    $this->loadComponent('AkkaFacebook.Graph', [
	    'app_id' => 'your-fb-app-id',
	    'app_secret' => 'your-fb-app-secret',
	    'app_scope' => 'email,public_profile', // https://developers.facebook.com/docs/facebook-login/permissions/v2.4
	    'redirect_url' => Router::url(['controller' => 'Users', 'action' => 'login'], TRUE), // This should be enabled by default
	    'post_login_redirect' => '' //ie. Router::url(['controller' => 'Users', 'action' => 'account'], TRUE)
	    // 'user_columns' => ['first_name' => 'fname', 'last_name' => 'lname', 'username' => 'uname', 'password' => 'pass'] //not required
    ]);
}

Usage

Note: FacebookHelper is automatically loaded by the Graph Component. If that is not desired, add 'enable_graph_helper' => false, to $this->loadComponent() above.

Helper Template File Setup
  • Add <?php echo $this->Facebook->initJsSDK(); ?> immediately after the opening <body> tag
Login Link (Customizable Facebook link <a href)

Reference - https://developers.facebook.com/docs/plugins/login-button

Optional Settings Array
* id 	-> Link id
* class -> Link class
* title -> Link title
* style -> Any html style
* label -> Hyperlink text
	
`<?php echo $this->Facebook->loginLink($options = []); ?>`
Like Button (Facebook Like)

Reference - https://developers.facebook.com/docs/plugins/like-button

Default Options
* 'action' => 'like', // like, recommend
* 'share' => true,
* 'width' => 450,
* 'show-faces' => true,
* 'layout' => 'standard' // standard, box_count, button_count, button

`<?php echo $this->Facebook->likeButton($options = []); ?>`
Share Button (Facebook Share)

Reference - https://developers.facebook.com/docs/plugins/share-button

Default Options
* 'layout' => 'button_count' // button_count/box_count/button/icon_link/icon/link

`<?php echo $this->Facebook->shareButton($options = []); ?>`
Send Button (Facebook Send)

Reference - https://developers.facebook.com/docs/plugins/send-button

Default Options
* 'width' => 50,
* 'height' => 30,
* 'colorscheme' => dark
	
`<?php echo $this->Facebook->sendButton($options = []); ?>`
Follow Button (Facebook Follow)

Reference - https://developers.facebook.com/docs/plugins/follow-button

Default Options
* 'width' => 300,
* 'height' => 100,
* 'colorscheme' => 'light',
* 'layout' => 'standard',
* 'show-faces' => false,
* 'kid-directed-site' => false
	
`<?php echo $this->Facebook->followButton($options = []); ?>`
Comments (Facebook Comments)

Reference - https://developers.facebook.com/docs/plugins/comments

Default Options
* 'colorscheme' => light, // light/dark
* 'mobile' => 'Auto-detected',
* 'num-posts' => 10,
* 'order-by' => 'social', // social/reverse_time/time
* 'width' => 550
	
`<?php echo $this->Facebook->comments($options = []); ?>`
Embedded Posts (Facebook Embedded Posts)

Reference - https://developers.facebook.com/docs/plugins/embedded-posts

Default Options
* 'width' => 500
	
`<?php echo $this->Facebook->embeddedPosts($options = []); ?>`
Embedded Video (Facebook Embedded Video)

Reference - https://developers.facebook.com/docs/plugins/embedded-video-player

Default Options
* 'href' => ''
* 'width' => 500
	
`<?php echo $this->Facebook->embeddedVideo($options = []); ?>`
Page Plugin (Facebook Page Plugin)

Reference - https://developers.facebook.com/docs/plugins/page-plugin

Default Options
* 'href' => 'https://www.facebook.com/facebook',
* 'height' => 300,
* 'hide-cover' => false,
* 'show-facepile' => true,
* 'show-posts' => false,
* 'width' => 500
	
`<?php echo $this->Facebook->page($options = []); ?>`

Coming Soon

  • Feed Dialog

Disclaimer

Although we have done many tests to ensure this plugin works as intended, we advise you to use it at your own risk. As with anything else, you should first test any addition to your application in a test environment. Please provide any fixes or enhancements via issue or pull request.

akkaweb/cakephp-facebook 适用场景与选型建议

akkaweb/cakephp-facebook 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2015 年 02 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cakephp」 「facebook」 「cakephp3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 akkaweb/cakephp-facebook 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 akkaweb/cakephp-facebook 我们能提供哪些服务?
定制开发 / 二次开发

基于 akkaweb/cakephp-facebook 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 5
  • Forks: 20
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-27