martin-georgiev/social-post-bundle

此包已被 弃用 且不再维护。未建议替代包。

Symfony 扩展包,用于同时在 Facebook、LinkedIn 和 Twitter 上发布相同的信息

v3.1.0 2020-05-31 13:31 UTC

README

升级?

请参阅 升级指南

这是什么?

这是一个用 Symfony 编写的 PHP 7.1 扩展包,它封装了 martin-georgiev/social-post - 一种轻松同时发布到多个社交网络的简单方法。目前,它集成了 Facebook、LinkedIn 和 Twitter。

如何安装它?

推荐方式是通过 Composer

composer require martin-georgiev/social-post-bundle

Symfony 集成

添加社交网络配置

# Usually part of config.yml
social_post:
    publish_on: [facebook, linkedin, twitter]         # List which Social networks you will be publishing to and configure your access to them as shown below
    providers:
        facebook:
            app_id: "YOUR-FACEBOOK-APP-ID"
            app_secret: "YOUR-FACEBOOK-APP-SECRET"
            default_access_token: "YOUR-FACEBOOK-NON-EXPIRING-PAGE-ACCESS-TOKEN"
            page_id: "YOUR-FACEBOOK-PAGE-ID"
            enable_beta_mode: true
            default_graph_version: "v2.8"             # Optional, also supports "mcrypt" and "urandom". Default uses the latest graph version.
            persistent_data_handler: "memory"         # Optional, also supports "session". Default is "memory".
            pseudo_random_string_generator: "openssl" # Optional, also supports "mcrypt" and "urandom". Default is "openssl".
            http_client_handler: "curl"               # Optional, also supports "stream" and "guzzle". Default is "curl".
        linkedin:
            client_id: "YOUR-LINKEDIN-APP-CLIENT-ID"
            client_secret: "YOUR-LINKEDIN-APP-CLIENT-SECRET"
            access_token: "YOUR-LINKEDIN-60-DAYS-LONG-USER-ACCESS-TOKEN"
            company_page_id: "YOUR-LINKEDIN-COMPANY-PAGE-ID"
        twitter:
            consumer_key: "YOUR-TWITTER-APP-CONSUMER-KEY"
            consumer_secret: "YOUR-TWITTER-APP-CONSUMER-SECRET"
            access_token: "YOUR-TWITTER-ACCESS-TOKEN"
            access_token_secret: "YOUR-TWITTER-ACCESS-TOKEN-SECRET"

注册扩展包

# Usually your app/AppKernel.php
<?php
// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new \MartinGeorgiev\SocialPostBundle\SocialPostBundle(),
        ];
        return $bundles;
    }
    // ...
}

发布测试消息

# Some Symfony container aware class
<?php
//...
$message = new \MartinGeorgiev\SocialPost\Message('your test message');
$container->get('social_post')->publish($message);

附加帮助

Twitter 对推文的定制功能有限。这意味着对于推文,只使用 messagelink 值(MartinGeorgiev\SocialPost\Message 实例)。

Facebook 不支持非过期用户访问令牌。相反,您可以获取永久页面访问令牌。使用此类令牌时,您可以像页面本身一样进行操作和发布。有关页面访问令牌的更多信息,请参阅官方 Facebook 文档。一些 Stackoverflow 答案(这里这里)也可能有所帮助。

许可

此包根据 MIT 许可证授权。