[英]Import twitter not working python
This is not working for me 这不适合我
import twitter
api= twitter.api(consumer_key,consumer_secret,access_token,access_token_secret)
//declared tokens value in the code.
It throws error : 'module' object is not callable 它抛出错误:'module'对象不可调用
I do not want to use tweepy for this. 我不想为此使用tweepy。
Unless I am misunderstanding which twitter library you are using, I think you want to be doing something like this (example retrieved by doing import twitter
and then help(twitter)
in an interactive Python interpreter): 除非我误解你正在使用哪个推特库,否则我认为你想要做这样的事情(例如通过在交互式Python解释器中执行
import twitter
然后help(twitter)
来检索):
from twitter import *
t = Twitter(auth=OAuth(token, token_key, con_secret, con_secret_key))
In your case, you are getting and error because twitter.api
is a submodule of the twitter
module, and (as the Traceback says) is not callable. 在你的情况下,你得到并且错误,因为
twitter.api
是twitter
模块的子模块,并且(如Traceback所说)不可调用。
Since it appears that you have the necessary values, you should try plugging them in (in the correct order - not the difference between my example, and the order of the arguments in your example) to OAuth()
or twitter.OAuth()
if you don't do a wild import. 由于您似乎拥有必要的值,因此您应该尝试将它们(以正确的顺序 - 不是我的示例与示例中的参数的顺序之间的差异)插入到
OAuth()
或twitter.OAuth()
你不做疯狂的导入。 Then you can pass that OAuth()
instance to Twitter
/ twitter.Twitter()
to create your API instance to query. 然后,您可以将该
OAuth()
实例传递给Twitter
/ twitter.Twitter()
以创建要查询的API实例。
So in your case, a (potentially) working example might be: 所以在你的情况下,一个(可能)工作的例子可能是:
import twitter
auth = twitter.OAuth(access_token, access_token_secret, consumer_secret, consumer_key)
api = twitter.Twitter(auth=auth)
I am unable to test this, since I don't want to set up API credentials, but I have used this library in the past. 我无法测试这个,因为我不想设置API凭据,但我过去曾使用过这个库。 I first learned about this API in this book chapter , which contains some helpful examples.
我在本书的第一章中首先了解了这个API,其中包含一些有用的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.