Revision #7 has been created by wei on Oct 26, 2010, 2:36:23 AM with the memo:
« previous (#6)
How To Connect With Twitter From Yii
</div><!-- yiiForm -->
<? } ?>
Capturing the Access Token
--------------------------After the user has authenticated with Twitter, your callback is called and the psYiiExtension library will pull out the new token and retrieve the permanent access token.
It is up to you to store this someplace. The library places the token in a user session state. You can retrieve the token via:
[...]Save these off for later use. You can use a session variable or store them in your database.
----------------------An alternate to this method is to use the <b>onUserAuthorized</b> event. This event is generated by the CPSOAuthComponent when authorization is complete. You must subclass CPSTwitterApi to capture this event and do with it what you please. Not a big deal, and kinda cool, no?
### Return trips to the site and reloading the token
After the session ends, the tokens are lost and you will need to load up your stored access tokens for the current user (or your site). This is done via the <b>CPSTwitterApi::loadData()</b> method.
It is up to you where you do this. Preferably, find a place where you actually need to use the Twitter API and load it there. Otherwise you'll end up loading it every time a page is loaded from your site and that's not very fast or Yii-like.