将 TwitterAPI 用于 OAuth 时出现语法错误
Syntax error while using TwitterAPI for OAuth
我正在尝试使用 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.
您在键入 from
.
之前点击了反引号 ` 字符(我假设是无意的)
棒球比赛不哭; Python
中没有反引号
编辑
这也是错误的:
api = TwitterAPI(sgKlULRabMMK8LWL1xlyQZ5Tp, 9CJQLJeJy1zab4Vb6z8bBo7danOYpgXmZRLAM0sQ8TWjgzeomr, 2478453955-DoOmd6G10VYvKNEKupbcNAxxdYrWCainf8URjDF, 00nxI4KDE7DekFcUDuUr60ziTuk03V9YQafuIYz7dYOUP1)
您必须在键周围加上引号,如下所示:
api = TwitterAPI("sgKlULRabMMK8LWL1xlyQZ5Tp",
"9CJQLJeJy1zab4Vb6z8bBo7danOYpgXmZRLAM0sQ8TWjgzeomr",
"2478453955-DoOmd6G10VYvKNEKupbcNAxxdYrWCainf8URjDF",
"00nxI4KDE7DekFcUDuUr60ziTuk03V9YQafuIYz7dYOUP1")
我正在尝试使用 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.
您在键入 from
.
棒球比赛不哭; Python
中没有反引号编辑
这也是错误的:
api = TwitterAPI(sgKlULRabMMK8LWL1xlyQZ5Tp, 9CJQLJeJy1zab4Vb6z8bBo7danOYpgXmZRLAM0sQ8TWjgzeomr, 2478453955-DoOmd6G10VYvKNEKupbcNAxxdYrWCainf8URjDF, 00nxI4KDE7DekFcUDuUr60ziTuk03V9YQafuIYz7dYOUP1)
您必须在键周围加上引号,如下所示:
api = TwitterAPI("sgKlULRabMMK8LWL1xlyQZ5Tp",
"9CJQLJeJy1zab4Vb6z8bBo7danOYpgXmZRLAM0sQ8TWjgzeomr",
"2478453955-DoOmd6G10VYvKNEKupbcNAxxdYrWCainf8URjDF",
"00nxI4KDE7DekFcUDuUr60ziTuk03V9YQafuIYz7dYOUP1")