I’m trying to create local auth Nonce and timestamp in my python file but it is giving me

{“errors”:[{“code”:32,“message”:“Could not authenticate you.”}]}

I’m using URL : https://api.twitter.com/1.1/account_activity/all/{{environment}}/subscriptions.json

strange part is when I’m trying with postman it is working but when I’m generating my own nonce and timestamp I’m getting the above error code 32

Code that I’m using
for nonce

from random import randrange
import urllib
nonce = str(base64.b64encode(bytes(str(randrange(10000000000)),'utf-8')),'utf-8')
nonce = urllib.parse.quote(nonce)

and for Timestamp

tstamp = str(int(round(time.time())))

Is there anything I’m missing ? I need to create a subscription so that my application can use Direct Messaging feature in twitter

I have followed this way to create nonce
This implies to me that I should do the following to generate the OAuth nonce:

  • Generate a random alphanumeric string (like aAbBcC123 but longer) with 32 characters
  • Convert the string to UTF8 data
  • Base64 encode the UTF8 data

but it did not work for me. Any help would be great

Why are you doing oauth things manually like that? Are there any special restrictions you have? Because it’s much more straight forward to use a library like requests-oauthlib · PyPI

Thanks @IgorBrigadir , It worked

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.