gfcapalbo / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

Patch : add a SetSource method to change the "from web" to "from source" status field on Twitter web site #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
You need first to send an email to Alex Payne(twitter) in order for him to
enable this feature for your application.

I'm using this with my Pwytter client.

I always get a server error when I try to attach a file, so here is the
patch gain (against 0.5) :

Index: twitter.py
===================================================================
@@ -902,6 +902,7 @@
     self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT
     self._InitializeRequestHeaders(request_headers)
     self._InitializeUserAgent()
+    self._InitializeJSONParameters()
     self._input_encoding = input_encoding
     self.SetCredentials(username, password)

@@ -1051,6 +1052,7 @@
       raise TwitterError("Text must be less than or equal to 140 characters.")
     url = 'http://twitter.com/statuses/update.json'
     data = {'status': text}
+    data.update(self._json_param)
     json = self._FetchUrl(url, post_data=data)
     data = simplejson.loads(json)
     return Status.NewFromJsonDict(data)
@@ -1292,6 +1294,17 @@
     self._request_headers['X-Twitter-Client'] = client
     self._request_headers['X-Twitter-Client-URL'] = url
     self._request_headers['X-Twitter-Client-Version'] = version
+    
+  def SetSource(self, source):
+    ''' Set the source parameters used to display the "from source" with 
+        each status on Twitter web site.
+        
+    Args:
+      source:
+        The source name as a string.  Will be sent to the server as
+         the 'source' JSON parameter.
+    '''
+    self._json_param['source'] = source

   def _BuildUrl(self, url, path_elements=None, extra_params=None):
     # Break url into consituent parts
@@ -1328,6 +1341,9 @@
                  (self._urllib.__version__, twitter.__version__)
     self.SetUserAgent(user_agent)

+  def _InitializeJSONParameters(self):
+    self._json_param = {}
+
   def _AddAuthorizationHeader(self, username, password):
     if username and password:
       basic_auth = base64.encodestring('%s:%s' % (username, password))[:-1]

Original issue reported on code.google.com by pierrejean.coudert on 14 Sep 2007 at 5:25

GoogleCodeExporter commented 9 years ago

Original comment by dclinton on 15 Sep 2007 at 7:15

GoogleCodeExporter commented 9 years ago

Original comment by dclinton on 15 Sep 2007 at 7:15

GoogleCodeExporter commented 9 years ago
Finally took care of this.  I changed the implementation somewhat -- can you 
please
verify in trunk?

Original comment by dclinton on 17 Apr 2008 at 4:06