Пример #1
0
def getTwitterInfo(request):
    if request.session.get("FOAUTH_TOKEN") and request.session.get("FOAUTH_TOKEN_SECERT"):
        user = MainUser.objects.get(user=request.user)
        accessToken = request.session.get("FOAUTH_TOKEN")
        accessTokenSecret = request.session.get("FOAUTH_TOKEN_SECERT")
        appId = "Use your api key"
        appSecret = "Use your api key"
        twitter = Twython(appId, appSecret, accessToken, accessTokenSecret)
        content = twitter.verify_credentials()
        print(content["id"])
        twitterSettings = UserSocialProfile(
            userSocialId=content["id"],
            accessToken=accessToken,
            accessTokenSecret=accessTokenSecret,
            serviceType="TWITTER",
            fullName=content["name"],
            user=user,
        )
        print(content["name"])
        twitterSettings.save()
        return redirect("/HMator/streamPage")
    else:
        return redirect("/HMator/saveTwitterSettings")
Пример #2
0
def getFacebookInfo(request):
    if request.session.get("accessToken"):
        user = MainUser.objects.get(user=request.user)
        accessToken = request.session.get("accessToken")
        requestedFields = "first_name,last_name,email,name"
        requestUrl = "https://graph.facebook.com/me?fields=" + requestedFields + "&access_token=" + accessToken
        result = urllib2.urlopen(requestUrl)
        content = json.load(result)

        facebookSetting = UserSocialProfile(
            userSocialId=content["id"],
            firstName=content["first_name"],
            lastName=content["last_name"],
            accessToken=accessToken,
            serviceType="FACEBOOK",
            emailAddress=content["email"],
            fullName=content["name"],
            user=user,
        )
        facebookSetting.save()
        return redirect("/HMator/streamPage")

    else:
        return redirect("/HMator/connectToFacebook")