Anyone calling food.find_id_for_barcode in Python?

151 views
Skip to first unread message

Rebecca Wang

unread,
Jul 6, 2020, 6:20:53 PM7/6/20
to FatSecret Platform API
I want to call the method "find_id_for_barcode"

I modified the fatsecret Python package by walexnelson to include the method. It should be simple enough, but no matter what barcode I pass in, it always returns "None"

The barcode is valid, e.g., 77567153012, since I tested it in Postman already, and it returned an actual food Id.

Below is my edition to the wrapper. Any ideas and help are much appreciated. Thx.

def food_get_food_id(self, barcode, region):
        params = {'method': 'food.find_id_for_barcode', 'barcode': barcode, 'region': region, 'format': 'json'}
        response = self.session.get(self.api_url, params=params)
        return self.valid_response(response)

Andrew VanZytveld

unread,
Feb 27, 2021, 4:43:23 PM2/27/21
to FatSecret Platform API
Here's the fix I found. Scroll to the very end of the code  for the valid_response function. There, right below the line reading, elif key in ('food', 'recipe', ....) add a final "else" condition: 
else:
    return response.json()[key]
Reply all
Reply to author
Forward
0 new messages