我正在尝试使用python中提供的TwitterAPI模块阅读推文,但我无法通过OAuth流程成功执行。
>>> from TwitterAPI import TwitterAPI
>>> api = TwitterAPI(sgKlULRabMMK8LWL1xlyQZ5Tp,
9CJQLJeJy1zab4Vb6z8bBo7danOYpgXmZRLAM0sQ8TWjgzeomr, 2478453955-
DoOmd6G10VYvKNEKupbcNAxxdYrWCainf8URjDF,
00nxI4KDE7DekFcUDuUr60ziTuk03V9YQafuIYz7dYOUP1)
File "<stdin>", line 1
api = TwitterAPI(sgKlULRabMMK8LWL1xlyQZ5Tp, 9CJQLJeJy1zab4Vb6z8bBo7danOYpgXmZRLAM0sQ8TWjgzeomr, 2478453955-DoOmd6G10VYvKNEKupbcNAxxdYrWCainf8URjDF, 00nxI4KDE7DekFcUDuUr60ziTuk03V9YQafuIYz7dYOUP1)
^
SyntaxError: invalid syntax
>>>
这给了我语法错误,基本上我所遵循的是
from TwitterAPI import TwitterAPI
api = TwitterAPI(consumer_key, consumer_secret, access_token_key,access_token_secret)
我在很少的地方看到其他人很少遇到同样的问题,被要求生成新的consumer_key,consumer_secret,access_token_key,access_token_secret,但我仍然面临同样的问题。
我希望你们可以拯救我,因为我是新手。
解决方案: -
1> Quotes was missing as said in answer below
2> The invalid syntax was also due to long line python issue.
答案 0 :(得分:2)
在点击from
之前,你点击了后面的`字符(我认为是偶然的)。
棒球没有哭; Python中没有反引号
修改强>
这也是错的:
api = TwitterAPI(sgKlULRabMMK8LWL1xlyQZ5Tp, 9CJQLJeJy1zab4Vb6z8bBo7danOYpgXmZRLAM0sQ8TWjgzeomr, 2478453955-DoOmd6G10VYvKNEKupbcNAxxdYrWCainf8URjDF, 00nxI4KDE7DekFcUDuUr60ziTuk03V9YQafuIYz7dYOUP1)
您必须在键周围加上引号,如下所示:
api = TwitterAPI("sgKlULRabMMK8LWL1xlyQZ5Tp",
"9CJQLJeJy1zab4Vb6z8bBo7danOYpgXmZRLAM0sQ8TWjgzeomr",
"2478453955-DoOmd6G10VYvKNEKupbcNAxxdYrWCainf8URjDF",
"00nxI4KDE7DekFcUDuUr60ziTuk03V9YQafuIYz7dYOUP1")