Twitter and oauth
Rok Žlender - March 17, 2009 - 07:42
| Project: | |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Description
Twitter OAuth beta is open for public. Before I start coding support for it into twitter module I'm just wondering if there was a decision made how this should be done. Is twitter module going to use oauth module http://drupal.org/project/oauth and simply use code in oauth test client for twitter purposes, use oauth php code http://code.google.com/p/oauth/, some third option.

#1
I created initial patch very rough around the edges but it works it uses http://drupal.org/project/oauth for oauth stuff. Not sure yet how old users will be converted. To test the patch you need:
#2
#3
Issue of converting old pass authenticated users is also being discussed on twitter dev list http://groups.google.com/group/twitter-development-talk/browse_thread/th...
#4
+1 subscribing
#5
+1 subscribing too, OAuth is the future :D
#6
Rerolled with recent twitter changes and a bunch of cleanup. Also more functions now use oauth. Problems still in the code
#7
Subscribing.
#8
did you do that for a site called 'NowPublic.com'?
at least that website name appears in my admin.
#9
Yes, it looks like the NowPublic.com site is hard-coded into the description and success messages for account setup. It should be changed to use variable_get('site_name')
#10
I've applied this patch, installed twitter.module on my site and have found the following:
- Yes, once you get the settings set up correctly while registering the Twitter application, it seems to authorize correctly.
- The string 'Now Public' appears to be hardwired in to the module/patch. So you get a message something like "You've successfully authorized Now Public to access your account." I'm guessing this should be a setting which defaults to the site name.
- I get the following error on the first page I load after running cron.php: "Unknown column 'tu.password' in 'field list' query: SELECT tu.screen_name, tu.password, ta.protected FROM twitter_user tu LEFT JOIN twitter_account ta ON tu.screen_name = ta.screen_name WHERE tu.import = 1 ORDER BY ta.last_refresh ASC LIMIT 0, 20 in sites/all/modules/twitter/twitter.module on line 188."
I did not patch an existing install of the Twitter module, so I'm guessing this error has something to do with a problem in the .install file.
- Schema module reports the error: "twitter_user.screen_name is part of the primary key but is not specified to be 'not null'."
- Schema module also reports (this may be same as above):
twitter_usercolumn screen_name:
declared: array('type' => 'varchar', 'length' => 255)
actual: array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => '')
#11
Also, the user/{uid}/edit/twitter page does not show anything in the Name or Description column:
#12
subscribing
#13
Subscribink!
#14
Ups NowPublic shouldn't be there :). I'll update patch with latest changes I made. Twitter is still actively changing stuff here and there but we don't have any problems with authenticating with oauth or authorizing accounts.
@Jjeff that screenshot indicates something didn't go as planned. Probably change to twitter oauth is not in patch yet.
#15
New patch with some more debugging and code that works with authorizing account with twitter. NowPublic branding removed. Marketing attempt failed :)
#16
With latest version of twitter module I don't get any schema module warnings. Also I can reproduce cron error. I missed cron func and it still tries to select password from db which does not exist anymore new patch is coming tmrw.
#17
does it mean i can already use twitter as login for my drupal page?
#18
@bara.munchies No, sign in with twitter is not supported in this patch. It only changes way your site calls twitter api.
#19
At the risk of sounding like a tool, is the above question & code re twitter credentials powering drupal authentication actually part of the roadmap? I could really use some of that about now.
Happy to do some small amount of sponsorship if necessary - hit me up if you're interested.
#20
Hey all,
Just wondering what the status of this patch is?
I have a client that needs what this provides. I don't usually use dev modules but this is the only option that I have. So... I'm about to start code review.
I'm applying twitter_4.patch to the DRUPAL-6--2 CVS tag. If I'm going about this wrong could someone say so?
Also, is there any central chat location (irc etc.) where development/testing/etc can be discussed in real time?
#21
Not sure if this is the right place to post this but it's related to the OAuth side of the project.
During testing I was getting an error from Twitter when trying to authorise an account via oauth and realised that I'd not setup the keys. This patch tests for the presence of both oauth keys and if either is absent it mentions that setup is required and provides a link to the setup form. It's assumed that this would happen during setup by the site owner/developer so there's no checking for permissions or anything.
twitter_4.patch should be applied before applying this patch.
#22
I've noticed that when you return from the Auth process there's 2 things that need fixing.
The first is a call to twitter_fetch_statuses() which fails. It looks like this is using the old user/pass approach. This is the error;
The other is that when you return it takes you to the user edit page. I would expect to return to the user edit twitter page and see that my new account is actually in the list.
I'm about to start on this. If anyone is already working on this or has a patch in need of review please let me know.
Otherwise, there will hopefully be a patch posted soon.
#23
twitter_fetch_statuses() calls _twitter_convert_xml_to_array().
This last function fails every time with "Exception: String could not be parsed as XML in /path/to/drupal/sites/ts2/modules/twitter/twitter.inc on line 541" This is thrown by SimpleXMLElement::__construct().
I've run the XML returned from Twitter through the W3C validator and that claims it's fine. I'm able to parse it through simplexml_load_string() okay. I'm currently rewriting the guts of this function to use this instead.
I've not been able to find an explanation as to why this doesn't work.
If _anyone_ knows why this doesn't work please let me know. I hate having to change things this way without a good explanation.
#24
Great...
simplexml_load_string() is loading the XML okay but calling ->getName() says I'm trying to access a method on a non-object.
print_r() says it's an Object.
get_class_methods() returns a list of methods too. One of which is getName(). :/
Giving up on this. Trying DOMDocument. :/
#25
Okay... This is getting a little retarded... I was just (okay, two days ago) on ##php on freenode and was asked to show the original error. I swapped out the file with an untouched one and everything worked. Now I have the mystery of why it didn't work and why it does work.
Code forensics commence. :/
#26
okay... If I take the debug output from a shell and hardcode the data being fed into SimpleXMLElement it parses fine. This suggests that it's a character encoding issue. Following this path of inquiry now. :/
#27
I'm giving up on this. It's doing my head in. It's not a character encoding issue as far as I can tell. Headers from the server claim utf-8. xml tag claims should be utf-8. Ensuring it's UTF-8 with mb_convert_encoding() and iconv() doesn't help. w3c claims the XML is well formed. xmllint claims it's well formed.
These all say to be the character encoding and the xml format are fine. I have no more ideas.
I'm not actually wanting to use the twitter module for managing the status messages anyway. All this time when I could have just worked around it. Ah... well.
I'm wanting to use the Twitter/Oauth facility to auth/approve/manage the accounts and sending messages only. To this end the fetching of statuses is redundant for me.
Instead I'm going to add a check box to the admin area that asks if the twitter module needs to manage the import of Tweets. This will allow for third party modules to be able to manage tweets themselves.
If anyone else has a similar problem as what I've been pulling hair over for the last few days I'd love to know what you figure out.
#28
The new GoTwitr site (currently on the d.o front page) implements some sort of twitter/oauth business - is that worth a look? Some of the code is freely available there.