[geeklog-hg] geeklog: Fixed Twitter login problems by updating OAuth Class to...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Feb 17 12:56:14 EST 2013


changeset 8947:69566ecb0030
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/69566ecb0030
user: Tom <websitemaster at cogeco.net>
date: Tue Feb 12 11:28:16 2013 -0500
description:
Fixed Twitter login problems by updating OAuth Class to use version 1.1 of the Twitter API. Patch provided by hiroron (feature request #0001506)

diffstat:

 system/classes/oauth/twitter.auth.class.php |   9 ++++++---
 system/classes/oauthhelper.class.php        |  12 +++++++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

diffs (86 lines):

diff -r 8821133f4aac -r 69566ecb0030 system/classes/oauth/twitter.auth.class.php
--- a/system/classes/oauth/twitter.auth.class.php	Sun Dec 30 10:41:10 2012 +0100
+++ b/system/classes/oauth/twitter.auth.class.php	Tue Feb 12 11:28:16 2013 -0500
@@ -5,7 +5,7 @@
 // | Geeklog 1.7                                                               |
 // +---------------------------------------------------------------------------+
 // | twitter.auth.class.php                                                    |
-// | version: 1.0.0                                                            |
+// | version: 1.0.1                                                            |
 // |                                                                           |
 // | Geeklog Distributed Authentication Module.                                |
 // +---------------------------------------------------------------------------+
@@ -40,10 +40,13 @@
 class twitterConsumer extends OAuthConsumerBaseClass {
     public $consumer_key = ''; // <-- Consumer key
     public $consumer_secret = '';  // <-- Consumer secret
+    public $method_requestToken = 'POST';
+    public $method_accessToken = 'POST';
+    public $dataformat = 'json';
     public $url_requestToken = 'https://api.twitter.com/oauth/request_token';
     public $url_authorize = 'https://api.twitter.com/oauth/authenticate';
     public $url_accessToken = 'https://api.twitter.com/oauth/access_token';
-    public $url_userinfo = 'http://api.twitter.com/1/account/verify_credentials.xml';
+    public $url_userinfo = 'http://api.twitter.com/1.1/account/verify_credentials.json';
 
     protected function _getCreateUserInfo($info) {
         $users = array(
@@ -81,7 +84,7 @@
         try {
             $this->consumer = new HTTP_OAuth_Consumer($this->consumer_key, $this->consumer_secret, $this->token, $this->token_secret);
             $this->consumer->accept($this->request);
-            $response = $this->consumer->sendRequest('http://api.twitter.com/1/direct_messages/new.xml', array('screen_name'=>$name, 'text'=>$msg), 'POST');
+            $response = $this->consumer->sendRequest('http://api.twitter.com/1.1/direct_messages/new.json', array('screen_name'=>$name, 'text'=>$msg), 'POST');
             if ($response->getStatus() !== 200) {
                 $this->errormsg = $response->getStatus() . ' : ' . $response->getBody();
                 COM_errorLog("TwitterAuth DM Error(".$response->getStatus()."/".$response->getBody().") TwitterId={$name}, DM={$msg}");
diff -r 8821133f4aac -r 69566ecb0030 system/classes/oauthhelper.class.php
--- a/system/classes/oauthhelper.class.php	Sun Dec 30 10:41:10 2012 +0100
+++ b/system/classes/oauthhelper.class.php	Tue Feb 12 11:28:16 2013 -0500
@@ -5,7 +5,7 @@
 // | Geeklog 1.8                                                               |
 // +---------------------------------------------------------------------------+
 // | oauthhelper.class.php                                                     |
-// | version: 1.0.0                                                            |
+// | version: 1.0.1                                                            |
 // |                                                                           |
 // | Geeklog Distributed Authentication Module.                                |
 // +---------------------------------------------------------------------------+
@@ -107,7 +107,7 @@
     protected $request = '';
     protected $consumer = '';
     protected $errormsg = '';
-    protected $shortapi = 'http://api.tr.im/api/trim_url.xml';
+    protected $shortapi = '';
     public $consumer_key = '';
     public $consumer_secret = '';
     public $url_requestToken = '';
@@ -117,6 +117,7 @@
     public $method_requestToken = 'GET';
     public $method_accessToken = 'GET';
     public $method_userinfo = 'GET';
+    public $dataformat = 'xml';
     public $cookietimeout = 300;    // google Callbacks 5min
     public $token = '';
     public $token_secret = '';
@@ -179,7 +180,11 @@
             if ($response->getStatus() !== 200) {
                 $this->errormsg = $response->getStatus() . ' : ' . $response->getBody();
             } else {
-                $userinfo = simplexml_load_string($response->getBody());
+                if ($this->dataformat == 'json') {
+                    $userinfo = json_decode($response->getBody());
+                } else {
+                    $userinfo = simplexml_load_string($response->getBody());
+                }
             }
         } catch (HTTP_OAuth_Consumer_Exception_Invalid_Response $e) {
             $this->errormsg = get_class($e) . ': ' . $e->getBody();
@@ -392,6 +397,7 @@
     }
 
     protected function _shorten($url) {
+        if (empty($this->shortapi)) { return $url; }
         $this->request->setUrl($this->shortapi.'?url='.$url);
         $this->request->setMethod('GET');
         $response = $this->request->send();



More information about the geeklog-cvs mailing list