Twitter and oauth

Rok Žlender - March 17, 2009 - 07:42
Project:Twitter
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

Rok Žlender - March 18, 2009 - 11:47

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:

AttachmentSize
twitter.oauth_.patch 18.63 KB

#2

Rok Žlender - March 18, 2009 - 12:06
Status:postponed (maintainer needs more info)» needs work

#3

Rok Žlender - March 24, 2009 - 07:17

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

GreenSkunk - March 31, 2009 - 16:21

+1 subscribing

#5

edmund.kwok - April 6, 2009 - 16:31

+1 subscribing too, OAuth is the future :D

#6

Rok Žlender - April 10, 2009 - 13:18

Rerolled with recent twitter changes and a bunch of cleanup. Also more functions now use oauth. Problems still in the code

  • No upgrade from regular users
  • No way to only specify account name for non privileged access. Every user must approve account through twitter page.
AttachmentSize
twitter.oauth_.patch 23.75 KB

#7

DanielTheViking - April 10, 2009 - 22:50

Subscribing.

#8

bara.munchies - May 4, 2009 - 14:05

did you do that for a site called 'NowPublic.com'?
at least that website name appears in my admin.

#9

tbartels - May 12, 2009 - 22:04

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

jjeff - May 23, 2009 - 12:43

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_user
  column screen_name:
    declared: array('type' => 'varchar', 'length' => 255)
    actual: array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => '')

#11

jjeff - May 23, 2009 - 12:48

Also, the user/{uid}/edit/twitter page does not show anything in the Name or Description column:

AttachmentSize
twitter-accounts.png 34.79 KB

#12

pribeh - May 25, 2009 - 23:29

subscribing

#13

NikLP - May 26, 2009 - 12:09

Subscribink!

#14

Rok Žlender - May 27, 2009 - 22:22

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

Rok Žlender - May 27, 2009 - 22:51

New patch with some more debugging and code that works with authorizing account with twitter. NowPublic branding removed. Marketing attempt failed :)

AttachmentSize
twitter.patch 25.85 KB

#16

Rok Žlender - May 27, 2009 - 23:02

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

bara.munchies - May 28, 2009 - 21:16

does it mean i can already use twitter as login for my drupal page?

#18

Rok Žlender - May 29, 2009 - 08:09

@bara.munchies No, sign in with twitter is not supported in this patch. It only changes way your site calls twitter api.

#19

NikLP - May 29, 2009 - 11:08

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

Gold - June 17, 2009 - 00:25

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

Gold - June 17, 2009 - 04:31

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.

AttachmentSize
twitter_pages_inc.patch 1.49 KB

#22

Gold - June 22, 2009 - 21:41

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;

warning: Missing argument 2 for twitter_fetch_statuses(), called in /home/gold/web/ts2/sites/ts2/modules/twitter/twitter.inc on line 491 and defined in /home/gold/web/ts2/sites/ts2/modules/twitter/twitter.inc on line 256.

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

Gold - June 23, 2009 - 04:08

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

Gold - June 23, 2009 - 04:59

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

Gold - June 24, 2009 - 22:32

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

Gold - June 25, 2009 - 00:01

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

Gold - June 25, 2009 - 02:42

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

NikLP - November 6, 2009 - 18:17

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.

 
 

Drupal is a registered trademark of Dries Buytaert.