jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
776 stars 234 forks source link

How to use it with CodeIgniter #47

Closed iturki closed 11 years ago

iturki commented 11 years ago

Any one tried using it with CI? I couldn't get it to work. If you know a way to do that or a CI port of this, please let us know.

-Thanks!

Mxrck commented 11 years ago

Just create a folder on "libraries" like "codebird" and put inside codebirt.php and cacert.pem:

/application/libraries/codebird/codebird.php /application/libraries/codebird/cacert.pem

remove the namespace from codebird.php

then just call library in your controller like this:

$this->load->library('codebird/codebird'); $this->codebird->setConsumerKey($consumerKey,$consumerSecret); $this->codebird->setToken($accessToken,$accessTokenSecret);

and use functions:

$response = $this->codebird->directMessages_new(Array('screen_name' => $user, 'text' => $message));

iturki commented 11 years ago

Thanks for the reply! Now the library is working, partially at least.

In my controller, I do the initialization in the __construct() (loading the library, setting the consumer keys). Then I have two different methods, signin() and auth(). signin() handles the part until the user is sent to Twitter. auth is where I get AccesTokens and store them in my database.

I couldn't figure out how to pass oauth_verifier from signin() to auth() to use it with $cb->oauth_accessToken().

Using sessions is not an option. I use ag_auth library which utilizes the session class. No matter what I saved in there, it will be unset.

Mxrck commented 11 years ago

Ok, oauth_verifier and oauth_token pass automatically to the callback URL by GET, you just need to set it site_url('auth') for 'oauth_callback' and Twitter do the rest, but if you need oauth_token_secret (and yes! you need it), you need to do a pre-register for your user, or simply, why don't you use CI Sessions flashdata ( or cookies ) [http://ellislab.com/codeigniter/user-guide/libraries/sessions.html]? to store data,

Easily you can do $this->session->set_flashdata('oauth_token_secret', 'value'); and recover the var in auth() by $this->session->flashdata('oauth_token_secret').

If you can't use flashdata Cookies solution is too much similar.

ZweiSteinSoft commented 11 years ago

Thanks @Mxrck for helping!