Get Responce by FatSecret Api With c#

120 views
Skip to first unread message

Luca Alba

unread,
Jun 12, 2019, 4:41:36 AM6/12/19
to FatSecret Platform API
I managed to get the token through this guide: https://platform.fatsecret.com/api/Default.aspx?screen=rapiauth2, but I couldn't get responce correctly. Where did I go wrong in the code?

Here is the code:

----- Start Code -----

            // --- Get responce --

            var http = new HttpClient();

            var byteArrayToken = Encoding.ASCII.GetBytes(data.access_token.ToString());
            http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Convert.ToBase64String(byteArrayToken));

            var valuesRequest = new Dictionary<string, string>
            {
               { "application", "json" },
            };

            var contentRequest = new FormUrlEncodedContent(valuesRequest);

            var responseRequest = await http.PostAsync("https://platform.fatsecret.com/rest/server.api?method=foods.search&search_expression=toast&format=json", contentRequest);

            var responseRequestString = await response.Content.ReadAsStringAsync();

-----End Code -----

The string responseRequestString should return the json string of the correct responce but it does not.

Where could the error be?

(Attached the image of the complete code also the one about the token.)

Thanks Luca.
Code.png

Jonathan Taylor

unread,
Dec 14, 2019, 5:24:35 PM12/14/19
to FatSecret Platform API
I haven't been able to test this yet because I have to wait for them to approve my IP but I think your second post needs to be a get.  A REST API uses the HTTP verbs: GET, POST, PUT and DELETE.  GET is for retrieving information, POST is for creating new stuff, PUT is for updating and DELETE is for deleting.
Reply all
Reply to author
Forward
0 new messages