Twitter premium not authorized

梦想的初衷 提交于 2021-02-05 06:00:11

问题


I attempted to run the code below and am getting an error that states: HTTP Error code: 403: Forbidden: Authentication succeeded but account is not authorized to access this resource.

from searchtweets import ResultStream, gen_rule_payload, load_credentials, collect_results

import requests

premium_search_args = load_credentials("/home/dirname/twitter_keys.yaml",
                                       yaml_key="search_tweets_premium",
                                       env_overwrite=False)


rule = gen_rule_payload("basketball", results_per_call=100) # testing with a sandbox account
print(rule)

from searchtweets import collect_results

tweets = collect_results(rule, 
                         max_results=100, 
                         result_stream_args=premium_search_args)


# print(tweets.all_text)

[print(tweet.all_text, end='\n\n') for tweet in tweets[0:10]];

My YAML file looks like this:

search_tweets_premium:
  account_type: premium
  endpoint: https://api.twitter.com/1.1/tweets/search/fullarchive/dev.json
  consumer_key: AAAAAAAAAAAAAAAAAAAAA
  consumer_secret: BBBBBBBBBBBBBBBBBBBBBBBBBBB

Only other thing to note is that I am using the free/sandbox service.

Any ideas if I am doing anything wrong in the code, the YAML, and/or within my Twitter developer account?


回答1:


You'll need to go to https://developer.twitter.com/en/account/environments

There you should be able to see the various development environments that you have. You can create one should they not have been created.

The dev environment label would then be the thing you use to replace in your endpoint.

In my example, it would be: https://api.twitter.com/1.1/tweets/search/fullarchive/development.json

If that still doesn't work, you might need to include a bearer token in your YAML file.



来源:https://stackoverflow.com/questions/55349475/twitter-premium-not-authorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!