Example #1
0
def get_auth_url(request):
    """ Requests url for an existing FS account binding to the specified user.

    :response_field string url: FS account binding URL.
    :response_field boolean success
    """

    fs = Fatsecret(settings.CONSUMER_KEY, settings.CONSUMER_SECRET)
    user_id = request.POST['user_id']
    if BotUser.objects.filter(bot_user_id=user_id).first() is None:
        return JsonResponse({"success": False, "error": "User with this id doesn't exist"})

    # Creating auth_url where token contains callback_url to our server page
    callback_url = urljoin(settings.REDIRECT_HOST, reverse('authenticate'))
    callback_url = urljoin(callback_url, '?user_id={}'.format(user_id))
    auth_url = fs.get_authorize_url(callback_url=callback_url)

    # Saving request token and secret for further FS instance creation in 'authenticate'
    user = BotUser.objects.get(bot_user_id=user_id)
    user.fs_request_token = fs.request_token
    user.fs_request_token_secret = fs.request_token_secret
    user.save()

    return JsonResponse({"success": True, "url": auth_url})
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))
Example #3
0
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))