!!! OAuth 1.0 Authentication Error with FatSecret API Requests in Python

51 views
Skip to first unread message

Александр Ким

unread,
Apr 28, 2024, 6:55:59 PMApr 28
to FatSecret Platform API
I am experiencing an issue with making API requests to the FatSecret platform using Python. While I am able to successfully make requests using Postman with OAuth 1.0 authentication, attempting the same via Python results in an error indicating a missing required OAuth parameter: oauth_signature_method.

Issue Description:
When making requests via Python using libraries such as requests_oauthlib or Authlib, the code for example:

import requests
from requests_oauthlib import OAuth1

url = "https://platform.fatsecret.com/rest/server.api"
auth = OAuth1(
    client_key='*****',
    client_secret='*****',
    resource_owner_key='*****',
    resource_owner_secret='*****',
    signature_method='HMAC-SHA1'
)
params = {
    'method': 'food_entries.get.v2',
    'date': 19824,
    'format': 'json'
}
response = requests.get(url, auth=auth, params=params)

the API consistently returns an error message:

"Missing required oauth parameter: oauth_signature_method"

However, when the same request is made through Postman with identical OAuth parameters, it succeeds without any issues. Below are the details of the request and the parameters used in both environments.

Request Details:

API Method: food_entries.get.v2
Date Parameter: 19824
Format: json
OAuth Parameters: oauth_consumer_key, oauth_token, oauth_signature_method, oauth_timestamp, oauth_nonce, oauth_version, and oauth_signature.

Successful Postman Request:

Consumer Key: *****
Consumer Secret: *****
Access Token: *****
Token Secret: *****
Signature Method: HMAC-SHA1
Python Setup:

Libraries used: requests_oauthlib and Authlib
Python Version: 3.8
I have tried multiple approaches to resolve this, including checking library versions, reconfiguring OAuth settings, and directly replicating the headers and parameters from Postman into Python code. Despite these efforts, the error persists.

Could you please provide guidance on how to resolve this issue or let me know if there are any specific requirements or settings for making OAuth-authenticated requests to FatSecret APIs using Python? Any assistance or insights you could offer would be greatly appreciated.

Thank you for your support and looking forward to your swift response.

Best regards,
Alexandr
Reply all
Reply to author
Forward
0 new messages