Session, Incomplete PHP Class
I am using cakePHP 2.x. Currently doing about Twitter OAuth, http://code.42dh.com/oauth/ .
function twitter_authentication()
{
//assume above coding is all correct.
$this->Session->write('twitter_request_token', ($requestToken));
$this->redirect('http://api.twitter.com/oauth/authenticate?force_login=true&oauth_token='.$requestToken->key); //I able to get $requestToken.
}
function twitter_login()
{
$requestToken = $this->Session->read('twitter_request_token');
$accessToken = $this->OAuthConsumer->getAccessToken('Twitter','https://api.twitter.com/oauth/access_token', $requestToken);
In function_login () function, I was unable to read the session and ended up with PhP Incomplete Class. If I execute $this->Session->write('twitter_request_token', serialize($requestToken));
and $requestToken = $this->Session->read(unserialize('twitter_request_token');
it works, but elsewhere I ran into an error caused by using a serialize and non-serialize session.
source to share
PHP Incomplete Class means that PHP does not have a class definition for the object you are loading.
Option A: Find out which class is the object when you write it to the session and make sure the class definition is loaded before loading the object.
Option B: Convert the object to stdClass
or an array before writing it and convert it back after loading. This can be more difficult than the first option.
source to share
OAuth.php The OauthToken class is pretty simple with two properties: a key and a secret. When you get the login url, you can store it in the session as an array:
CakeSession::write('Twitter.requestToken', array(
'key' => $requestToken->key,
'secret' => $requestToken->secret
));
Then create your own OAuthToken when calling OAuthClient-> getAccessToken () like this:
$sessionRequestToken = CakeSession::read('Twitter.requestToken');
$accessToken = $twitterClient->getAccessToken('https://api.twitter.com/oauth/access_token',
new OAuthToken($sessionRequestToken['key'], $sessionRequestToken['secret']));
Should be ready to go:
if ($accessToken) {
$twitterClient->post($accessToken->key, $accessToken->secret,
'https://api.twitter.com/1/statuses/update.json', array('status' => 'My balls smells like A-1 sauce. #science'));
}
source to share