Я хочу использовать твиттер API с Nim.
Но я не могу решить ошибку.
{"errors": [{"code": 85, "message": "Проверка списка не пройдена: имя списка не может быть пустым."}]}
Успешная аутентификация.
Что я делаю ошибку, используя Twitter API или
используя библиотеку Nim oauth1,
отправка сообщения методом body?
import tables, oauth1, strutils, httpclient, json
proc parseResponseBody(body: string): Table[string, string] =
let responses = body.split("&")
result = initTable[string, string]()
for res in responses:
let r = res.split("=")
result[r[0]] = r[1]
proc getRequestToken(consumerKey, consumerKeySecret: string): Table[string, string] =
let response = getOAuth1RequestToken(
"https://api.twitter.com/oauth/request_token",
consumerKey,
consumerKeySecret,
isIncludeVersionToHeader = true)
if response.status == "200 OK":
return parseResponseBody(response.body)
else:
assert(false, response.body)
proc getAccessToken(consumerKey, consumerKeySecret, requestToken, requestTokenSecret, verifier: string): Table[string, string] =
let response = getOAuth1AccessToken(
"https://api.twitter.com/oauth/access_token",
consumerKey,
consumerKeySecret,
requestToken,
requestTokenSecret,
verifier,
isIncludeVersionToHeader = true)
if response.status == "200 OK":
return parseResponseBody(response.body)
else:
assert(false, response.body)
let
consumerKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
consumerKeySecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
let requestToken = getRequestToken(consumerKey, consumerKeySecret)
echo getAuthorizeUrl("https://api.twitter.com/oauth/authorize", requestToken["oauth_token"])
let verifier = readLine(stdin)
let accessTokens = getAccessToken(
consumerKey,
consumerKeySecret,
requestToken["oauth_token"],
requestToken["oauth_token_secret"],
verifier)
let param = %*{"name": "chage","mode": "private","description": "description"}
let response = oauth1Request(
"https://api.twitter.com/1.1/lists/create.json",
consumerKey,
consumerKeySecret,
accessTokens["oauth_token"],
accessTokens["oauth_token_secret"],
httpMethod = HttpPost,
body = $param
)
echo response.body