> Would isAuthenticated just check if the token/secret are set? It would check that the access token and secret are known (in the session in my case, could be in a DB) and possibly check account/ verify_credentials too.
> I had > assumed (perhaps incorrectly) that the object would be instantiated at > a point where you have the required credentials. Checking to see if > you have already set the token/secret on an object would be a trivial > addition, but do you have a use case of when/why you'd need to do > that? (note: I looked over your code but haven't tried it or checked it in details) I started from Abraham's sample code (see link sent earlier) where access token and secret are saved in sessions (at the moment, I don't really need to save it differently...) and used to instantiate the OAuth object. At every request in the same session, these are used to instantiate the object, but before your app is authorized, you don't know the access token and secret for a user. So, the very first time, I need to instantiate an object with only the consumer key and secret. So, by having the constructor working with the 2 or 4 arguments as above, I need to manage in the controllers these sessions variables to know if I'm instantiating with: -consumer key and secret (first time); -CK/CS + request token/secret (after app is authorized on twitter.com, to request the access token and secret); -or with CK/CS + access token/secret (for all next requests with access to account) I made the changes I wanted (even though some error checking is definitely missing) and it works as far as I can tell. I'm mostly wondering if there is a reason why the libraries were written that way and if it's a "proper" thing to do. Or maybe I'm just missing something :) I'm not 100% satisfied with this either. By the way, I like your use of __call() to create the API url from the method name. Quite flexible when the API evolves... Cheers, Tim > > On Jun 3, 2:57 pm, Tim <[email protected]> wrote: > > > > > Hello, > > > (note: this question might actually be more a general programming > > question rather than specific to Twitter) > > I have been looking at a few PHP libraries to use OAuth with Twitter > > (thanks to Abraham and Jason amongst others) and noticed that most (if > > not all) of them have a constructor more or less like that: > > function __construct($consumer_key, $consumer_secret, $oauth_token = > > NULL, $oauth_token_secret = NULL) > > called with 2 or 4 arguments depending on where in the OAuth process > > we are. (access token already known or not) > > > That usually means that the status of the OAuth process is to be > > managed in the controllers when creating the object. > > If you take the example from Abraham's > > code:http://github.com/abraham/twitteroauth/blob/6b28e9e689d44a569576f7267... > > there's a lot of session variables management (granted, this code is > > provided as an example and advertised as "not for production"...) > > > Basically, I feel that I'd rather do something like: > > > $twitter = new TwitterOAuth(); > > $twitter->getPublicTimeline(); > > if ($twitter->isAuthenticated()) { $twitter->getFriendsTimeline();} > > etc. > > > with the logic of if the access token is known being handled by the > > class itself. > > > Since all the libraries I have seen didn't go this way (and were > > written by people who most probably know what they're doing a lot more > > than I do), I am wondering if I make any sense. > > > Thanks for your help, > > > Tim
