def authenticate(request): """ Page where user is redirected from a FS account binding confirmation page to complete FS account binding. """ fs = Fatsecret(settings.CONSUMER_KEY, settings.CONSUMER_SECRET) if request.GET.get('oauth_verifier', None): user_id = int(request.GET['user_id']) verifier_pin = request.GET['oauth_verifier'] # Changing FS instance to use variables from 1st step of 3-Legged OAuth user = BotUser.objects.get(bot_user_id=user_id) fs.request_token = user.fs_request_token fs.request_token_secret = user.fs_request_token_secret session_token = fs.authenticate(verifier_pin) logger.info("Successful authentication. Token is {}, user id is {}".format(session_token, user_id)) # Updating user fields user.fatsecret_account = 'OLD' user.fatsecret_oauth_token = session_token[0] user.fatsecret_oauth_token_secret = session_token[1] user.save() return render(request, "fat_secret_api/auth_complete.html") else: return JsonResponse({"error": "Authentication cannot be completed: OAUTH verifier is not set"})
print("Food Search Results: {}".format(len(foods))) print("{}\n".format(foods)) food = fs.food_get("1345") print("Food Item 1345") print("{}\n".format(food)) recipes = fs.recipes_search("Tomato Soup") print("Recipe Search Results:") print("{}\n".format(recipes)) recipe = fs.recipe_get("88339") print("Recipe 88339") print("{}\n".format(recipe)) # Test Calls with 3 Legged Oauth print("\n\n ------ OAuth Example ------ \n\n") print(fs.get_authorize_url()) session_token = fs.authenticate(input("\nPIN: ")) foods = fs.foods_get_most_eaten() print("Most Eaten Food Results: {}".format(len(foods))) recipes = fs.recipes_search("Enchiladas") print("Recipe Search Results: {}".format(len(recipes))) profile = fs.profile_get() print("Profile: {}".format(profile))