Getting started

What you need to know in order to build applications with the Guardian

1) Register for a key

While we're still in beta you will first need an API key in order to access the service. Submit a request for a key by giving us your contact information and telling us about what you plan to do.
When you have your key set the ApiKey in your config file:
<add key="ApiKey" value="xxxxxxxx"/>

2) Try some sample code

            //A simple content search
            var op = new OpenPlatformSearch();
            var results = op.Search(new ContentSearchParameters
            {
                Query = "Nina Nastasia",
                Count = 20,
            });

            Console.WriteLine("Number of results: " + results.Count);
            foreach (var item in results.Results)
            {
                Console.WriteLine(item.Headline);
            }
            //A content search with filters
            var op = new OpenPlatformSearch();
            var parameters = new ContentSearchParameters
                                 {
                                     Query = "prince",
                                     Count = 20,
                                     Filters = new List<string>{"music"}
                                 };
            
            var results = op.Search(parameters);

            Console.WriteLine("Number of results: " + results.Count);
            foreach (var item in results.Results)
            {
                Console.WriteLine(item.Headline);
            }
            //Get an item by Id
            var op = new OpenPlatformSearch();
            var item = op.Item(353757375);

            Console.WriteLine("author name: " + item.Byline);
            if(item.Type == "article")
                Console.WriteLine(item.TypeSpecific.Body);
            //Get a list of different content types with a count for each
            var op = new OpenPlatformSearch();
            var results = op.Search(new ContentSearchParameters {Count = 100});

            var typeCounts = results.Results
                .GroupBy(c => c.Type)
                .Select(c => new {ContentType = c.Key, Count = c.Count()});

            foreach(var typeCount in typeCounts)
            {
                Console.WriteLine("Type: " + typeCount.ContentType + " Count: " + typeCount.Count);
            }

3) Get help

If you have feature requests or bugs to report please share them with us in the Guardian API Talk group.
We don't offer support with our free service, but we will do our best to answer your questions. You may find others who can answer your questions there, too.
For more general information about the OpenPlatform see our home page on guardian.co.uk

4) Show your work

Tell us what you're doing with the Content API. Post a link to your site or describe your work in the Guardian API Talk group.
Last edited Oct 22 2009 at 8:46 AM by rbates, version 14

 

Want to leave feedback?
Please use Discussions or Reviews instead.

Updating...
© 2006-2010 Microsoft | Get Help | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2010.2.24.16331