【问题标题】:cakephp2 i want to only tweetcakephp2 我只想发推文
【发布时间】:2014-01-16 08:00:09
【问题描述】:

我使用 cakephp2.x 并使用这个 Consuming OAuth-enabled APIs with CakePHP http://code.42dh.com/oauth/ 我只想发推文。但我现在不能。

  1. 下载消费包并放入app/vender/OAuth

  2. 在 PostsController 中编写此代码 App::import('Vendor', 'OAuth/OAuthClient');

    public function add() {
            $client = $this->createClient();
            $requestToken = $client->getRequestToken('https://api.twitter.com/oauth/request_token',
    

    'http://' 。 $_SERVER['HTTP_HOST'] 。 '/lol​​ch/posts'); 如果($requestToken){ $this->Session->write('twitter_request_token', $requestToken); $this->redirect('https://api.twitter.com/oauth/authorize?oauth_token=' . $requestToken->key); } } 公共函数回调(){ $requestToken = $this->Session->read('twitter_request_token'); $client = $this->createClient(); $accessToken = $client->getAccessToken('https://api.twitter.com/oauth/access_token', $requestToken); $client->post($accessToken->key, $accessToken->secret, 'https://api.twitter.com/1.1/statuses/update.json', array('status' => '你好世界!')); 私有函数 createClient() { return new OAuthClient('my key', 'my secret'); }

我应该在哪里更改代码??

【问题讨论】:

    标签: twitter cakephp-2.0


    【解决方案1】:

    您可以使用 https://github.com/LubosRemplik/CakePHP-Twitter-API-Plugin‎ 插件或其他用于 cakephp 的 twitter 插件并阅读那里的文档以应用您想要的东西。使用现成的插件比重新发明轮子更容易。

    【讨论】:

      猜你喜欢
      • 2017-11-22
      • 2011-10-29
      • 2018-02-15
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多