1
votes

I use cakephp2.x and use this Consuming OAuth-enabled APIs with CakePHP http://code.42dh.com/oauth/ I only want to be able to tweet. But I can't now.

  1. Download consuming package and put app/vender/OAuth

  2. Write this code in 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/posts'); 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'); }

Where should I change the code??

1

1 Answers

0
votes

You can use https://github.com/LubosRemplik/CakePHP-Twitter-API-Plugin‎ plugin or other twitter plugin for cakephp and read the documentation there to apply what you want. It is easy to use ready made plugin than reinventing the wheel.