使用Python的Twitter参与API

时间:2018-07-14 14:02:57

标签: python-3.x twitter oauth-2.0 gnip

我正在尝试使用python oauth2来获取参与数据,因为我有enterprise account用于Twitter。

我可以使用以下端点https://api.twitter.com/1.1/statuses/home_timeline.json

从时间轴中获取推文

但是现在我正在尝试使用参与API,具有相同的访问详细信息,它给出的错误为{u'errors': [u'Your account could not be authenticated. Reason: Unknown Authorization Type']}

以下是该代码正在使用的:

def engagement_api(url, consumer_key, consumer_secret_key,access_key,access_secret_key, http_method="POST",http_headers={'Content-type': 'application/json'}):#def oauth_req(url, key, secret, http_method="GET", post_body=””, http_headers=None):
    consumer = oauth2.Consumer(key=consumer_key, secret=consumer_secret_key)
    token = oauth2.Token(key=access_key, secret=access_secret_key)
    client = oauth2.Client(consumer, token)
    resp, content = client.request( url, method=http_method,headers=http_headers,body=urllib.urlencode({'status': params}))
    return content

if __name__ == '__main__':
    engagements = engagement_api('https://data-api.twitter.com/insights/engagement/totals', consumer_key, consumer_secret_key,access_key,access_secret_key) 

我正在尝试使用端点https://data-api.twitter.com/insights/engagement/totals。当我进行搜索时,我的脑海中充满了疑问

  1. 我们不能使用相同的凭据直接获取参与细节吗?
  2. 什么是gnip?
  3. 我们需要拥有gnip帐户来获取参与度数据吗?

你能请人帮我吗?

0 个答案:

没有答案