2017-06-20 47 views
0

這是我的代碼:如何在使用Tweepy包裝器將媒體附加到DM上時傳遞附件參數?

mediaID = 877121579854856193L print mediaID response = "here's a pic" b = api.send_media(user_id =status.direct_message['sender_id'], text =response, attachment={'type':'media','media_id': mediaID}) print b 我已經定義在Tweepy的api.py的新方法send_media其類似於send_direct_message() 的定義如下:

@property def send_direct_message(self): """ :reference: https://dev.twitter.com/rest/reference/post/direct_messages/new :allowed_param:'user', 'screen_name', 'user_id', 'text' """ return bind_api( api=self, path='/direct_messages/new.json', method='POST', payload_type='direct_message', allowed_param=['user', 'screen_name', 'user_id', 'text'], require_auth=True ) @property def send_media(self): """ :reference: https://dev.twitter.com/rest/reference/post/direct_messages/new :allowed_param:'user', 'screen_name', 'user_id', 'text' """ return bind_api( api=self, path='/direct_messages/new.json', method='POST', payload_type='media', allowed_param=['user', 'screen_name', 'user_id', 'text','attachement'], require_auth=True )

雖然在請求我正在獲取媒體類型,而不是DirectMessage,我沒有得到DM中的任何圖片,只有文本:「這是一張圖片」

請求在控制檯中的響應:

媒體(_api =,recipient_id_str = u'2956391868' ,發件人= {u'follow_request_sent ':虛假,u'has_extended_profile':虛假,u'profile_use_background_image ':真,u'default_profile_image':假,U 'id':106111046,u'profile_background_image_url_https':u'https://abs.twimg.com/images/themes/theme15/bg.png',u'verified':False,u'translator_type':u'none',u'profile_text_color':u'333333',u'profile_image_url_https':u' https://pbs.twimg.com/profile_images/839688948360216576/95sFtYJs_normal.jpg',u'profile_sidebar_fill_color':u'C0DFEC',u'entities':{u'description':{u'urls':[]}},u'followers_count':38,u'profile_sidebar_border_color':u'A8C7F7 ',u'id_str':u'106111046',u'profile_background_color'.......

回答

相關問題