inori/twitter-app-bundle

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

无客户端的Twitter应用实例,帮助自动化项目Twitter更新

安装次数: 1,777

依赖者: 1

建议者: 0

安全性: 0

星标: 8

关注者: 0

分支: 8

类型:symfony-bundle

dev-master 2015-07-14 04:55 UTC

This package is not auto-updated.

Last update: 2020-01-21 13:32:03 UTC


README

该项目已不再由我维护。如果您想接管,请通过inoryy@gmail.com与我联系

简介

TwitterAppBundle在本质上只是twitteroauth客户端和symfony2之间简单的代理包。它仅适用于无客户端应用。如果您想将Twitter登录/注册等功能添加到您的应用程序中,请考虑使用FOS/TwitterBundle。

示例用法

此包的示例用例可以是自动发送关于系统某些事件的Twitter消息(来自您的项目账户)。

安装

带有依赖项

将此包和Abraham Williams的Twitter库添加到您的应用程序中

[twitteroauth]
    git=http://github.com/abraham/twitteroauth.git

[InoriTwitterAppBundle]
    git=http://github.com/Inori/InoriTwitterAppBundle.git
    target=bundles/Inori/TwitterAppBundle

使用composer

将此包添加到您的composer.json中

// composer.json
{
    // ...
    require: {
        // ...
        "inori/twitter-app-bundle": "master"
    }
}

将命名空间 Inori 注册到项目的自动加载引导脚本中

//app/autoload.php
$loader->registerNamespaces(array(
    // ...
    'Inori'    => __DIR__.'/../vendor/bundles',
    // ...
));

将此包添加到应用程序的内核中

//app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Inori\TwitterAppBundle\InoriTwitterAppBundle(),
    );
}

在YAML配置中配置 twitter_app 服务

#app/config/config.yml
inori_twitter_app:
    file: %kernel.root_dir%/../vendor/twitteroauth/twitteroauth/twitteroauth.php
    consumer_key: xxxxxx
    consumer_secret: xxxxxx
    oauth_token: xxxxxx
    oauth_token_secret: xxxxxx

注意!有关如何获取密钥/令牌的信息,请参阅Twitter开发者文档。快速了解以下内容。

使用TwitterApp

如果设置正确,则可以像这样开始使用TwitterApp

// ...
$ta = $this->container->get('twitter_app');
$messages = $ta->getDirectMessages();

TwitterApp提供了一些基本方法以简化使用(推文、关注等),但对于大多数API功能,您应通过getApi()方法使用twitteroauth,如下所示

// ...
$ta = $this->container->get('twitter_app');
$trends = $ta->getApi()->get('trends');

获取Twitter API令牌

  • Twitter开发者页面登录
  • 创建您的应用程序
  • 通过我的应用程序访问您的应用程序配置页面
  • 在那里,您将在 OAuth设置 下看到 Consumer keyConsumer secret
  • 您的访问令牌 下,您应该看到 Access tokenAccess token secret,如果没有,则简单地点击 "Recreate my access token"
  • 确保 Access level读取、写入和直接消息,如果不是,则转到 设置 选项卡,在 应用程序类型 -> 访问 下选择 读取、写入和访问直接消息