Skip to content

Commit

Permalink
Use a user's Twitter ID to follow them instead of their Twitter handle.
Browse files Browse the repository at this point in the history
  • Loading branch information
ykdojo committed Dec 5, 2018
1 parent 272737d commit 2f58d0d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions users/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from django.shortcuts import render
from django.http import HttpResponse
import tweepy
from .keys import *
from .keys import * # this is for tweepy
from allauth.socialaccount.models import SocialAccount

def login(request):
username = None
if not request.user.is_authenticated:
current_user = request.user
if not current_user.is_authenticated:
return render(request, 'login.html')

username = request.user.username
twitter_account = SocialAccount.objects.filter(user = current_user)[0]
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.create_friendship(username)
# TODO: store some info about if we already follow them or not
api.create_friendship(twitter_account.uid)
# TODO: store some info about if we already follow them or not.
return render(request, 'login.html')

0 comments on commit 2f58d0d

Please sign in to comment.