示例#1
0
        protected async Task <Dictionary <string, object> > Request(string search, NutritionixReqType nutritionixReqType)
        {
            var      keysRapidApi = new RapidAPIKeys();
            RapidAPI RapidApi     = new RapidAPI(keysRapidApi.Project, keysRapidApi.Key);

            var keysNutritionix   = new NutritionixApiKeys();
            List <Parameter> body = new List <Parameter>
            {
                new DataParameter("applicationSecret", keysNutritionix.ApplicationSecret),
                new DataParameter("foodDescription", search),
                new DataParameter("applicationId", keysNutritionix.ApplicationId)
            };

            try
            {
                return(await RapidApi.Call("Nutritionix", nutritionixReqType.ToString(), body.ToArray()));
            }
            catch (RapidAPIServerException e)
            {
                //TODOO:  need the implemet
            }
            catch (Exception e)
            {
                //TODOO:  need the implemet
            }

            return(null);
        }
示例#2
0
        public JObject getCurrentUser()
        {
            body.Add(new DataParameter("accessToken", "3883859036.1677ed0.6fd4d9681b074f02ad55a0aed7dab08f"));

            try
            {
                Dictionary <string, object> response = RapidApi.Call("Instagram", "getCurrentUser", body.ToArray()).Result;
                object payload;
                if (response.TryGetValue("success", out payload))
                {
                    JObject o = JObject.Parse(payload.ToString());
                    string  profilepicture = (string)o.SelectToken("data.profile_picture");
                    string  bio            = (string)o.SelectToken("data.bio");
                    string  username       = (string)o.SelectToken("data.username");
                    string  fullname       = (string)o.SelectToken("data.full_name");
                    // int follows = (int)o.SelectToken("counts.follows");

                    dataofinsta.Add(profilepicture);
                    dataofinsta.Add(bio);
                    dataofinsta.Add(username);
                    dataofinsta.Add(fullname);
                    // dataofinsta.Add(follows);



                    Console.WriteLine(dataofinsta[0]);
                    Console.WriteLine(dataofinsta[1]);
                    Console.WriteLine(dataofinsta[2]);
                    Console.WriteLine(dataofinsta[3]);
                    //Console.WriteLine(dataofinsta[4]);
                }
                else
                {
                }
            }
            catch (RapidAPIServerException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(dataofinsta);
        }
        //To call an API:
        public static void CallApi()
        {
            List <Parameter> body = new List <Parameter>();

            body.Add(new DataParameter("ParameterKey1", "ParameterValue1"));
            body.Add(new DataParameter("ParameterKey2", "ParameterValue2"));
            try
            {
                Dictionary <string, object> response = RapidApi.Call("APIName", "FunctionName").Result;
                object payload;
                if (response.TryGetValue("success", out payload))
                {
                }
                else
                {
                }
            }
            catch (RapidAPIServerException e)
            {
            }
            catch (Exception e)
            {
            }
        }
示例#4
0
        public async Task <List <FoodItem> > SearchFoodByName(string search)
        {
            List <Parameter> body = new List <Parameter> {
                new DataParameter("applicationSecret", "136102bad14d027d885ecd731f5a92d0"),
                new DataParameter("foodDescription", search),
                new DataParameter("applicationId", "4d8b69d2")
            };



            /*    List<Parameter> body = new List<Parameter> {
             *
             * new DataParameter("applicationSecret", "12707924c854726c16ec685b23b25d5e"),
             * new DataParameter("foodDescription", search),
             * new DataParameter("applicationId", "7dc87896")
             *
             * };*/


            /*  List<Parameter> body = new List<Parameter> {
             *
             * new DataParameter("applicationSecret", "f4b41ced83da477aae9ac35d1ff77a24"),
             * new DataParameter("foodDescription", search),
             * new DataParameter("applicationId", "650bd306")
             *
             * };*/



            List <FoodItem> foodSearchArr = new List <FoodItem>();

            try
            {
                if (!check_con())
                {
                    throw new Exception("ERROR Connecting To Internet. Please Connect To Internet!");
                }

                var temp = await RapidApi.Call("Nutritionix", "searchFoods", body.ToArray());

                if (temp.TryGetValue("success", out object payload))
                {
                    var foodArrayCSharp = SearchFoodsJsonResults.FromJson(JsonConvert.SerializeObject(temp));
                    foreach (var item in foodArrayCSharp.Success[0].Common)
                    {
                        foodSearchArr.Add(
                            new FoodItem(
                                item.TagId,
                                item.FoodName,
                                item.Photo.Thumb
                                ));
                    }
                }
                else
                {
                    JObject jObject  = JObject.Parse(json: JsonConvert.SerializeObject(temp));
                    var     error    = jObject.SelectToken("error");
                    var     errorMsg = jObject.SelectToken("error").First.First;
                    throw new Exception("Error,\n API problem: " + errorMsg.ToString() + ",\n Please contact the technician man.");
                }

                return(foodSearchArr);
            }
            catch (RapidAPIServerException e)
            {
                throw new Exception(e.Message);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }