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


#1

Hi All,
I still can access APIs of Twitter by python-twitter at https://github.com/bear/python-twitter 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?
Thanks,


#2

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.


#3

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',
                       consumer_secret='myserect',
                       access_token_key='mytoken',
                       access_token_secret='mytoken-secret')
 
 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 f.id == status_id:
         print('Found ID Favorite is ', f.id)
         favcount = 1
 
 if favcount == 0:
     print('NOT found ID Like')

And raise error:

 Traceback (most recent call last):
   File "mytwitter.py", 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/api.py", 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/api.py", line 4908, in _ParseAndCheckTwitter
     self._CheckForTwitterError(data)
   File "/home/ubuntu/project/python-projects/bounty-program/env27/local/lib/python2.7/site-packages/twitter/api.py", line 4927, in _CheckForTwitterError
     raise TwitterError(data['error'])
 twitter.error.TwitterError: Not authorized.

Please advise :slight_smile:


#4

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


#5

@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.


#6

Thank @Aurelia :slight_smile:
Let me check.


#7