How to request APIs after turning "[X] Protect your Tweets" on?


Hi All,
I still can access APIs of Twitter by python-twitter at well. After turning the account setting on " Protect your Tweets" I got an issue as “twitter.error.TwitterError: Not authorized”.
Could you help me why it happen?


Hi @n2k3bu1 - what exactly are you trying to do when you get this error: access Tweets, Direct Messages, or something else?

After enabling “Protect your Tweets” on your Twitter account, you may need to regenerate your tokens in order for it to work.


Hi @Aurelia,
The exact message is “Not authorized.” as call API GetFavourite. It just happens when turning on “Protect your Tweets” on the user’s profile setting that is NOT my profile setting.

My code as following:

 import twitter
 api = twitter.Api(consumer_key='mykey',
 status_id = 20983213241321321
 user_id = api.GetUser(screen_name='user-account').id
 print("GetFavorites - Likes: check user if any likes My-company-twitter")
 favcount = 0
 favourites = api.GetFavorites(user_id=user_id, count=1, max_id=status_id)
 for f in favourites:
     if == status_id:
         print('Found ID Favorite is ',
         favcount = 1
 if favcount == 0:
     print('NOT found ID Like')

And raise error:

 Traceback (most recent call last):
   File "", line 22, in <module
     favourites = api.GetFavorites(user_id=user_id, count=1, max_id=status_id)
   File "/home/ubuntu/project/python-projects/bounty-program/env27/local/lib/python2.7/site-packages/twitter/", line 3508, in GetFavorites
     data = self._ParseAndCheckTwitter(resp.content.decode('utf-8'))
   File "/home/ubuntu/project/python-projects/bounty-program/env27/local/lib/python2.7/site-packages/twitter/", line 4908, in _ParseAndCheckTwitter
   File "/home/ubuntu/project/python-projects/bounty-program/env27/local/lib/python2.7/site-packages/twitter/", line 4927, in _CheckForTwitterError
     raise TwitterError(data['error'])
 twitter.error.TwitterError: Not authorized.

Please advise :slight_smile:


Have you re-authenticated the user to your app after changing their settings?


@n2k3bu1 - Note that this behaviour is to be expected if you are trying to access data from an account that fulfills the following conditions:

(1) is not the Twitter account linked to your developer credentials,
(2) is a private account,
(3) does not follow you and you do not follow them.


Thank @Aurelia :slight_smile:
Let me check.