Google Image Search API JSON interface

link
a questo link potete trovare i riferimenti per effettuare delle ricerche di immagini in google con risposta in formato json, qui di seguito un piccolo esempio di classe c# per richiamare tale funzionalità

public class GoogleProxy
    {
        private string filterSearch = String.Empty;
        private int startPage = 0;
        private string url = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q={0}&start={1}";
 
        public GoogleProxy(string filter, int page = 0)
        {
            filterSearch = filter;
            startPage = page;
        }
 
        public GoogleSearch Search()
        { 
            string requestUrl = String.Format(url,filterSearch,startPage.ToString());
 
            HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                var stream = response.GetResponseStream();
                var sr = new StreamReader(stream);
                var content = sr.ReadToEnd();
                JavaScriptSerializer js = new JavaScriptSerializer();
                GoogleSearch results = js.Deserialize<GoogleSearch>(content);
 
                return results;
            }
        }
    }
 
    public class GoogleImage
    {
        public string GsearchResultClass { get; set; }
        public string width { get; set; }
        public string height { get; set; }
        public string imageId { get; set; }
        public string tbWidth { get; set; }
        public string tbHeight { get; set; }
        public string unescapedUrl { get; set; }
        public string url { get; set; }
        public string visibleUrl { get; set; }
        public string title { get; set; }
        public string titleNoFormatting { get; set; }
        public string originalContextUrl { get; set; }
        public string content { get; set; }
        public string contentNoFormatting { get; set; }
        public string tbUrl { get; set; }
    }
 
    public class GooglePage
    {
        public string start { get; set; }
        public int label { get; set; }
    }
 
    public class GoogleSearchInfo
    {
        public string resultCount { get; set; }
        public List<GooglePage> pages { get; set; }
        public string estimatedResultCount { get; set; }
        public int currentPageIndex { get; set; }
        public string moreResultsUrl { get; set; }
        public string searchResultTime { get; set; }
    }
 
    public class GoogleResponse
    {
        public List<GoogleImage> results { get; set; }
        public GoogleSearchInfo cursor { get; set; }
    }
 
    public class GoogleSearch
    {
        public GoogleResponse responseData { get; set; }
        public object responseDetails { get; set; }
        public int responseStatus { get; set; }
    }

posted @ lunedì 16 dicembre 2013 18:25

Print

Comments on this entry:

# Abc

Left by Abc at 04/01/2017 13:06
Gravatar
[url=abc.com]abc[/url]

# re: Google Image Search API JSON interface

Left by abc at 04/01/2017 13:07
Gravatar

# re: Google Image Search API JSON interface

Left by William at 04/01/2017 13:09
Gravatar
API is complicated language when first time i try to learn this language then i seen lot's of problems but now i am good in API.Thanks for this code.
official order forms

# re: Google Image Search API JSON interface

Left by Deshawn at 04/01/2017 13:48
Gravatar
I read this post which is about API. This lenguge is my favorite. Thanks for posting.
<ahref="http://labelprintingsuppliers.com/">Design printed labels suppliers
Comments have been closed on this topic.
«novembre»
domlunmarmergiovensab
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567