定制 jonasva/laravel-facebook-insights 二次开发

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

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

jonasva/laravel-facebook-insights

Composer 安装命令:

composer require jonasva/laravel-facebook-insights

包简介

Facebook page insights integration with Laravel

README 文档

README

FacebookInsights provides a quick way to access insights of a facebook page with the Facebook OpenGraph API v2. It works with a permanent access token so no user interaction is required. A common usage would be to have a statistics dashboard that needs to regularly fetch insights of a facebook page.

Installation

To get the latest version of FacebookInsights require it in your composer.json file.

"jonasva/laravel-facebook-insights": "dev-master"

(For Laravel 4, please check the documentation of the Laravel4 branch of this repository)

Run composer update jonasva/laravel-facebook-insights to install it.

Once FacebookInsights is installed you need to register its service provider with your application. Open config/app.php and find the providers key.

'providers' => array(

    Jonasva\FacebookInsights\FacebookInsightsServiceProvider::class,

)

A Facade for easy access is also included. You can register the facade in the aliases key of your config/app.php file.

'aliases' => array(

    'FacebookInsights' => Jonasva\FacebookInsights\Facades\FacebookInsights::class,

)

Publish the configurations

Run this on the command line from the root of your project:

$ php artisan vendor:publish

A configuration file will be published to config/facebook-insights.php

Config

Facebook App and Page information

To use this package, you'll need to setup your Facebook App ID, App secret, (permanent) access token and Page ID. For more information about this check the config file.

Cache

Facebook GraphApi responses get cache for 1 day by default. You can change this by altering the cache-lifetime.

Usage

The package contains several useful methods to fetch facebook insights with the OpenGraph API. Methods can be called by using the facade FacebookInsights. For example:

    use FacebookInsights; // this goes above your class declaration

    // ...

    $startDate = new \DateTime('2015-03-15');
    $endDate = new \DateTime('2015-03-25');
    // fetch your page's total impressions for a given period
    $totalImpressions = FacebookInsights::getPageTotalImpressions($startDate, $endDate);

Methods

This package currently provides insights for Page and Post objects. That said, any other OpenGraph queries can also be done by simply using the following method:

    /**
     * Construct a facebook request
     *
     * @param string $query
     * @param array $params (optional)
     * @param string $method (optional)
     * @param string $object (optional)
     *
     * @return GraphObject
     */
    public function performGraphCall($query, $params = [], $object = null, $method = 'GET')

Page Insights

Get the total amount of page fans (aka followers, people who liked the page)

    /**
     * Get the total amount of page fans (people who liked the page)
     *
     * @return int
     */
    public function getPageTotalFans()

Get new fans per day for a given period

    /**
     * Get new page fans per day for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPageNewFansPerDay(\DateTime $startDate, \DateTime $endDate)

Get the total number of new page fans for a given period

    /**
     * Get the total number of new page fans for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return int
     */
    public function getPageTotalNewFans(\DateTime $startDate, \DateTime $endDate)

Get a page's impressions (The total number of impressions seen of any content associated with your Page) per day for a given period

    /**
     * Get the page impressions per day for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPageImpressionsPerDay(\DateTime $startDate, \DateTime $endDate)

Get the total number of page impressions for a given period

    /**
     * Get the total number of page impressions for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return int
     */
    public function getPageTotalImpressions(\DateTime $startDate, \DateTime $endDate)

Get a page's consumptions (The number of times people clicked on any of your content) per day for a given period

    /**
     * Get the page consumptions per day for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPageConsumptionsPerDay(\DateTime $startDate, \DateTime $endDate)
    {

Get the total number of page consumptions for a given period

    /**
     * Get the total number of page consumptions for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return int
     */
    public function getPageTotalConsumptions(\DateTime $startDate, \DateTime $endDate)

Get like, comment, share, rsvp, claim and answer counts for a page's posts grouped per day for a given period

    /**
     * Get a page's positive feedback per day for a given period
     * The following actions are categorized as positive feedback:
     * like, comment, link (share), rsvp (respond to an event), claim, answer
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPagePositiveFeedbackPerDay(\DateTime $startDate, \DateTime $endDate)

Get accumulated (total) like, comment, share, rsvp, claim and answer counts for a page's posts grouped per day for a given period

    /**
     * Get a page's accumulated positive feedback for a given period
     * The following actions are categorized as positive feedback:
     * like, comment, link (share), rsvp (respond to an event), claim, answer
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     *
     * @return array
     */
    public function getPageTotalPositiveFeedback(\DateTime $startDate, \DateTime $endDate)

Get a specific insight for a page for a given period. Insights can be found here: https://developers.facebook.com/docs/graph-api/reference/v2.2/insights#page_impressions

    /**
     * Get a specific insight for a page for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     * @param string $insight
     * @param string $period (optional)
     *
     * @return int
     */
    public function getPageInsight(\DateTime $startDate, \DateTime $endDate, $insight, $period = 'day')

Get a page's posts for a given period. This is not really an insight, but is needed to get post ID's which can later be used to collect post insights.

    /**
     * Get the page's posts for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     * @param int $limit
     *
     * @return array
     */
    public function getPagePosts(\DateTime $startDate, \DateTime $endDate, $limit = null)

Switching to another page

It is also possible to dynamically switch to another page, to fetch its insights / posts. You can use the switchPage method for that:

    /*
     * Switch to another page to get insights of
     *
     * @param string $pageId
     * @param string $accessToken
     */
    public function switchPage($pageId, $accessToken)

Example:

    FacebookInsights::switchPage('other page id', 'other page's permanent access token');

Post Insights

Post specific insights can only be collected by period lifetime, so no date range needs to be given.

Get a post's impressions

    /**
     * Get a post's impressions
     *
     * @param string $postId
     *
     * @return int
     */
    public function getPostImpressions($postId)

Get a post's consumptions

    /**
     * Get a post's consumptions
     *
     * @param string $postId
     *
     * @return int
     */
    public function getPostConsumptions($postId)

Get a specific insight for a post. Post insights can be found here: https://developers.facebook.com/docs/graph-api/reference/v2.2/insights#post_impressions

    /**
     * Get a specific insight for a post
     *
     * @param string $insight
     * @param string $postId
     *
     * @return array
     */
    public function getPostInsight($postId, $insight)

Get the page's posts with calculated insights for a given period

    /**
     * Get the page's posts with calculated insights for a given period
     *
     * @param \DateTime $startDate
     * @param \DateTime $endDate
     * @param int $limit
     *
     * @return array
     */
    public function getPagePostsBasicInsights(\DateTime $startDate, \DateTime $endDate, $limit = null)

jonasva/laravel-facebook-insights 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 27
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 5
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-15