Python проблемы с параметрами в oauth.Request.from_consumer_and_token - PullRequest
0 голосов
/ 06 марта 2020

Я пытаюсь достичь конечной точки подсчета в Premium API Twitter. У меня есть следующее:

# The endpoint to hit
function = '/search/fullarchive/:label/counts'

# Put the endpoint together with the API URL
the_url = "https://api.twitter.com/1.1/tweets/{}.json".format(function)

# The parameters of your call to the endpoint
parameters = {'query': '#dkpol', 'fromDate': 201801010000, 'toDate': 201901010000, 'bucket': 'day'}

# Defines a request for data from the Twitter API (?)
req = oauth.Request.from_consumer_and_token(oauth_consumer,
token = oauth_token,
http_method = "GET",
http_url = the_url,
parameters = parameters)

req.sign_request(signature_method_hmac_sha1, oauth_consumer, oauth_token)
headers = req.to_header()
encoded_post_data = None
url = req.to_url()
opener = urllib.request.OpenerDirector()
opener.add_handler(http_handler)
opener.add_handler(https_handler)

# Make the request to the Twitter API for data
# The result, in the object "out", will contain the data
out = opener.open(url, encoded_post_data, timeout = 60)

response = json.loads(out.read().decode('utf-8'))

Я получаю сообщение об ошибке 404: «Ресурс не найден по URL-адресу, на который был отправлен запрос, вероятно, из-за неправильного URL-адреса».

Вызов GET работал, когда я использовал только:

function = 'users/lookup' 
parameters = [('user_id', "15xxxxxxx")]

Может кто-нибудь помочь мне найти ошибку? Это неправильный URL, который я написал, или что-то не так с синтаксисом параметров, указанных в коде?

...