Use Twitter API in Celery task - need to use access_key and access_secret from auth user

I have the following function in my that will send me the authorised user’s key tokens. I can then manually amend these tokens for my Twitter API function locally to run the program.

def like(request):
oauth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
access_key = request.session['access_key_tw']
access_secret = request.session['access_secret_tw']

   'Auth Codes', # subject
   access_key + access_secret, # message
   DEFAULT_FROM_EMAIL, # from email

return render(request, "home.html")

However having to do this manually isn’t great and for security reasons I don’t want to be emailing them to myself to then run a code locally. I want to push the function to a celery task so that I don’t need the sendmail() at all. My celery task would look like this after liking.delay() being called within like() -

def liking(self):

oauth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
oauth.set_access_token(access_key, access_secret)
api = tweepy.API(oauth)

** Rest of my code using the Twitter API **

Basically I need to somehow get the str variables for the access_key and access_secret over to my task but request is not defined in Celery so I cannot use access_key = request.session[‘access_key_tw’]. Any help would be greatly appreciated as it’s driving me mad!

You can pass the parameters in your call to liking.delay, and then reference them in your liking function. See the delay docs for more information.

Thanks! It was the (bind=True) that was preventing me from passing the parameters properly