I have the following function in my views.py 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']
send_mail(
'Auth Codes',
'access key - ' + os.environ['oaccess_key'] + '\n' + 'access_secret - ' + os.environ['oaccess_secret'],
DEFAULT_FROM_EMAIL,
[DEFAULT_FROM_EMAIL],
)
return render(request, "home.html")
However having to do this manually isn't great and for security reasons I'd rather not have them emailed. 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() -
@app.task(bind=True)
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 **
What I have tried:
I have tried simply importing the variables or adding making them global but Heroku will not let me deploy when doing this.
I have also tried to set the access_key and access_secret as environment variables but this returns as 'none'.