简体   繁体   English

使用python的twitter api发布消息

[英]using twitter api from python to post messages

diveintopython3 tells how you can post a message to identi.ca diveintopython3告诉您如何向identi.ca发布消息

>>> from urllib.parse import urlencode
>>> import httplib2
>>> httplib2.debuglevel = 1
>>> h = httplib2.Http('.cache')
>>> data = {'status': 'Test update from Python 3'}
>>> h.add_credentials('diveintomark', 'MY_SECRET_PASSWORD', 'identi.ca')    
>>> resp, content = h.request('https://identi.ca/api/statuses/update.xml',
...     'POST',                                                             
...     urlencode(data),                                                    
...     headers={'Content-Type': 'application/x-www-form-urlencoded'})

I thought I'd do the same with twitter.. 我以为我会用twitter做同样的事情..

Then,I found out that they don't use basic authentication,but uses oauth.. so I thought this library would help 然后,我发现他们不使用基本身份验证,但使用oauth ..所以我认为这个库会有所帮助

But the docs show that I need some kind of consumer_key etc for authorisation.. 但文档显示我需要某种consumer_key等授权..

I have a twitter account where I login with mygmailid@gmail.com as username and mypassword as password.Is there some way I can use these for authorization? 我有一个Twitter帐户,我用mygmailid@gmail.com作为用户名登录, mypassword作为密码登录。有什么方法我可以使用这些进行授权吗?

You need to register your app to get that consumer key, and many other essentials informations. 您需要注册您的应用程序以获取该使用者密钥以及许多其他必需品信息。

Here you go : https://dev.twitter.com/apps 您可以访问: https//dev.twitter.com/apps

Some explanations : https://dev.twitter.com/docs/faq#7447 一些解释: https//dev.twitter.com/docs/faq#7447

As you are about to play with the API please note this link to the API console, I found it always really useful : https://dev.twitter.com/console 当您即将使用API​​时请注意这个API控制台的链接,我发现它总是非常有用: https//dev.twitter.com/console

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM