예제 #1
0
        public void LoadData(string board, string category)
        {
            string url        = "https://api.pinterest.com/v1/boards/" + board + "/pins/?access_token=Ab1rhweqeChC5tmKgfILFrE6t-TYFNwv7w_soZhELMu2AwBCWQAAAAA&fields=id,note,image";
            int    total_pins = CountPinsBoard(board);

            for (int i = 0; i <= (total_pins / 25); i++)
            {
                CallApi call = new CallApi();
                var     json = call.Get(url);
                if (json != null)
                {
                    JObject pinObj = new JObject(JObject.Parse(json));
                    var     pins   = pinObj["data"];
                    if (!IsNullOrEmpty(pins))
                    {
                        Parse_Data(pins, category);
                    }
                    var next = pinObj["page"]["next"];
                    if (!IsNullOrEmpty(next))
                    {
                        url = next.ToString();
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
예제 #2
0
        private int CountPinsBoard(string board)
        {
            int     count = 0;
            string  url   = "https://api.pinterest.com/v3/pidgets/boards/" + board + "/pins/";
            CallApi call  = new CallApi();
            var     json  = call.Get(url);

            if (json != null)
            {
                JObject jsonObj   = new JObject(JObject.Parse(json));
                var     jsonBoard = jsonObj["data"]["board"];
                if (!IsNullOrEmpty(jsonBoard))
                {
                    count = Int32.Parse(jsonBoard["pin_count"].ToString());
                }
            }
            return(count);
        }
예제 #3
0
        public string Pin(string boardname, string note, string image, string link, int type)
        {
            boardname = boardname.Replace(" ", "-");
            string url = "https://api.pinterest.com/v1/pins/?access_token=Ab1rhweqeChC5tmKgfILFrE6t-TYFNwv7w_soZhELMu2AwBCWQAAAAA&fields=id%2Clink%2Cnote%2Curl";

            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(boardname))
            {
                sb.Append("&board=" + HttpUtility.UrlEncode("besttshirtsusa/" + boardname));
            }
            if (!string.IsNullOrEmpty(link))
            {
                if (type == 2)
                {
                    sb.Append("&link=" + HttpUtility.UrlEncode(link));
                }
                else
                {
                    sb.Append("&link=" + HttpUtility.UrlEncode("https://besttshirtusa.com/product/" + link));
                }
            }
            if (!string.IsNullOrEmpty(note))
            {
                sb.Append("&note=" + HttpUtility.UrlEncode(note));
            }
            if (!string.IsNullOrEmpty(image))
            {
                sb.Append("&image_url=" + HttpUtility.UrlEncode("https:" + image.Replace("https:", "")));
            }

            string  data = sb.ToString().Substring(1);
            CallApi call = new CallApi();

            return(call.Post(url, data));
        }