@@ -912,13 +912,15 @@ def PostMedia(self, status, media, possibly_sensitive=None,
912912 raise TwitterError ("The twitter.Api instance must be authenticated." )
913913
914914 url = '%s/statuses/update_with_media.json' % self .base_url
915+ print url
915916
916917 if isinstance (status , unicode ) or self ._input_encoding is None :
917918 u_status = status
918919 else :
919920 u_status = unicode (status , self ._input_encoding )
920921
921922 data = {'status' : status }
923+
922924 if media .startswith ('http' ):
923925 data ['media' ] = urllib2 .urlopen (media ).read ()
924926 else :
@@ -936,10 +938,75 @@ def PostMedia(self, status, media, possibly_sensitive=None,
936938 if display_coordinates :
937939 data ['display_coordinates' ] = 'true'
938940
941+ print media
939942 json = self ._RequestUrl (url , 'POST' , data = data )
940943 data = self ._ParseAndCheckTwitter (json .content )
941944 return Status .NewFromJsonDict (data )
942945
946+ def PostMultipleMedia (self , status , media , possibly_sensitive = None ,
947+ in_reply_to_status_id = None , latitude = None ,
948+ longitude = None , place_id = None ,
949+ display_coordinates = False ):
950+ '''
951+ Post a twitter status message from the authenticated user with a
952+ picture attached.
953+
954+ Args:
955+ status:
956+ the text of your update
957+ media:
958+ location of media(PNG, JPG, GIF)
959+ possibly_sensitive:
960+ set true is content is "advanced"
961+ in_reply_to_status_id:
962+ ID of a status that this is in reply to
963+ lat:
964+ location in latitude
965+ long:
966+ location in longitude
967+ place_id:
968+ A place in the world identified by a Twitter place ID
969+ display_coordinates:
970+
971+ Returns:
972+ A twitter.Status instance representing the message posted.
973+ '''
974+ if not self .__auth :
975+ raise TwitterError ("The twitter.Api instance must be authenticated." )
976+
977+ upload_url = self .base_url .replace ('api' , 'upload' )
978+ url = '%s/media/upload.json' % upload_url
979+
980+ if isinstance (status , unicode ) or self ._input_encoding is None :
981+ u_status = status
982+ else :
983+ u_status = unicode (status , self ._input_encoding )
984+
985+ data = {}
986+
987+ if type (media ) is not list :
988+ raise TwitterError ("Must by multiple media elements" )
989+
990+ media_ids = ''
991+ for m in media :
992+
993+ if m .startswith ('http' ):
994+ data ['media' ] = urllib2 .urlopen (m ).read ()
995+ else :
996+ data ['media' ] = open (str (m ), 'rb' ).read ()
997+
998+ json = self ._RequestUrl (url , 'POST' , data = data )
999+ data = self ._ParseAndCheckTwitter (json .content )
1000+ media_ids += str (data ['media_id_string' ])
1001+
1002+ data = {'status' : status }
1003+
1004+ url = '%s/statuses/update.json' % self .base_url
1005+ url += "?media_ids=" + media_ids
1006+
1007+ json = self ._RequestUrl (url , 'POST' , data = data )
1008+ data = self ._ParseAndCheckTwitter (json .content )
1009+
9431010 def PostUpdates (self , status , continuation = None , ** kwargs ):
9441011 '''Post one or more twitter status messages from the authenticated user.
9451012
@@ -3368,6 +3435,7 @@ def _RequestUrl(self, url, verb, data=None):
33683435 '''
33693436 if verb == 'POST' :
33703437 if data .has_key ('media' ):
3438+ print "sending data"
33713439 try :
33723440 return requests .post (
33733441 url ,
0 commit comments