cakephp2我只想发推文

问题描述 投票:1回答:1

我使用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']。 '/ lolch /帖'); if($ requestToken){$ this-> Session-> write('twitter_request_token',$ requestToken); $ this-> redirect('https://api.twitter.com/oauth/authorize?oauth_token='。$ requestToken-> key); public function callback(){$ 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'=>'hello world!')); private function createClient(){return new OAuthClient('my key','my secret'); }

我应该在哪里更改代码?

twitter cakephp-2.0
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.