Code Monkey home page Code Monkey logo

msnews-sdk-csharp's Introduction

Microsoft News API SDK for C#

Integrate the Microsoft News API into your .NET project! To obtain your api key and ocid, you can send us an e-mail! Build status

Give us your feedback

Your feedback is important to us.

  • To let us know about any questions or issues you find in the documentation, submit an issue in this repository.
  • We also encourage you to fork, make the fix, and do a pull request of your proposed changes. See Contributing section for contributing guidelines.

Quick Start

1. Clone project

You can clone Microsoft News API SDK for C# using following git command

cd %YOUR_PROJECT_DIR%
git clone https://github.com/microsoft/msnews-sdk-csharp

2. Open solution

Open MSN.Library.MicrosoftNewsAPI.SDK.Csharp.sln solution in Visual Studio

3. Set your credentials

Set your credentials ( APIKEY and OCID) at MicrosoftNewsClient constructor. Sample usage as follows,

MicrosoftNewsClient client  = new MicrosoftNewsClient("YOUR_APIKEY", "YOUR_OCID");

4. Sample API calls

You check Program.cs file located under Examples project to further usage of SDK

using System;
using MicrosoftNewsAPI.SDK;
using MicrosoftNewsAPI.SDK.Models;

namespace Examples
{
    class Program
    {
        static void Main(string[] args)
        {
            MicrosoftNewsClient client;
            if (args.Length == 2)
                client = new MicrosoftNewsClient(args[0], args[1]);
            else
                client = new MicrosoftNewsClient("YOUR_APIKEY", "YOUR_OCID");
            

            Console.WriteLine("Endpoint /news/feed");
            var responseGetNewsFeed = client.GetNewsFeed();
            if (responseGetNewsFeed != null) {
                for (int i = 0; i < responseGetNewsFeed.Value.Count; i++) {
                    Console.WriteLine("Number of subCards : " + responseGetNewsFeed.Value[i].SubCards.Count);
                    foreach (var card in responseGetNewsFeed.Value[i].SubCards)
                    {
                        Console.WriteLine("(MicrosoftNewsApiContractsFeedItemViewV1) Title :" + card.Title);
                    }
                }
            }
            else {
                Console.WriteLine("Invalid request or response from GetNewsFeed()");
            }
            
            
            Console.WriteLine("Endpoint /news/markets");
            var responseGetNewsMarkets = client.GetNewsMarkets();
            if (responseGetNewsMarkets != null) {
                for (int i = 0; i < responseGetNewsMarkets.Value.Count; i++) {
                    Console.WriteLine("(MsnTagsDataModelTagEntityLibMarket) Culture :" + responseGetNewsMarkets.Value[i].Culture);
                }
            }
            else {
                Console.WriteLine("Invalid request or response from GetNewsMarkets()");
            }
            
            
            Console.WriteLine("Endpoint /news/topics");
            var responseGetNewsTopics = client.GetNewsTopics();
            if (responseGetNewsTopics != null) {
                for (int i = 0; i < responseGetNewsTopics.Value.Count; i++) {
                    Console.WriteLine("Number of subCards : " + responseGetNewsTopics.Value[i].SubCards.Count);
                    foreach (var card in responseGetNewsTopics.Value[i].SubCards)
                    {
                        if (card is MsnTagsDataModelTagEntityLibArtifact)
                        {
                            var artifact = (MsnTagsDataModelTagEntityLibArtifact) card;
                            Console.WriteLine("(MsnTagsDataModelTagEntityLibArtifact) Title : " + artifact.Title);
                        
                        }
                        else if (card is MsnTagsDataModelTagEntityLibSysTag)
                        {
                            var sysTag = (MsnTagsDataModelTagEntityLibSysTag) card;
                            Console.WriteLine("(MsnTagsDataModelTagEntityLibSysTag) Name : " + sysTag.Name);
                        }
                        else if (card is MsnTagsDataModelTagEntityLibCompositeCard)
                        {
                            var compositeCard = (MsnTagsDataModelTagEntityLibCompositeCard) card;
                            Console.WriteLine("(MsnTagsDataModelTagEntityLibCompositeCard) Composite Card : " + compositeCard.Title);
                        }
                        else
                        {
                            Console.WriteLine("ERROR!");
                        }
                    }
                }
            }
            else {
                Console.WriteLine("Invalid request or response from GetNewsTopics()");
            }
            
            
        }
    }
}

Expected Output

Endpoint /news/feed
Number of subCards : 10
(MicrosoftNewsApiContractsFeedItemViewV1) Title :Trump questions patriotism of whistleblower in firestorm
(MicrosoftNewsApiContractsFeedItemViewV1) Title :Fashion hits and misses
(MicrosoftNewsApiContractsFeedItemViewV1) Title :Best pictures from the 2019 Emmys
(MicrosoftNewsApiContractsFeedItemViewV1) Title :Woman sexually assaulted by Brock Turner gives '60 Minutes' interview
(MicrosoftNewsApiContractsFeedItemViewV1) Title :Ranking the 7 NFL teams with 3-0 records
(MicrosoftNewsApiContractsFeedItemViewV1) Title :5 TV shows and people who don't deserve their Emmy awards - sorry
(MicrosoftNewsApiContractsFeedItemViewV1) Title :Kasich on Ukraine: 'People would be going crazy' if Obama did this
(MicrosoftNewsApiContractsFeedItemViewV1) Title :Overstock plummets 19% as CFO resigns
(MicrosoftNewsApiContractsFeedItemViewV1) Title :Tekashi 69: Can he disappear after testifying against the Bloods?
(MicrosoftNewsApiContractsFeedItemViewV1) Title :This company has filed 10,000 appeals to Trump's tariffs
Endpoint /news/markets
(MsnTagsDataModelTagEntityLibMarket) Culture :hi-in
(MsnTagsDataModelTagEntityLibMarket) Culture :es-xl
(MsnTagsDataModelTagEntityLibMarket) Culture :es-mx
(MsnTagsDataModelTagEntityLibMarket) Culture :en-au
(MsnTagsDataModelTagEntityLibMarket) Culture :pt-br
(MsnTagsDataModelTagEntityLibMarket) Culture :es-ar
(MsnTagsDataModelTagEntityLibMarket) Culture :es-co
(MsnTagsDataModelTagEntityLibMarket) Culture :en-in
(MsnTagsDataModelTagEntityLibMarket) Culture :fr-be
(MsnTagsDataModelTagEntityLibMarket) Culture :pt-pt
Endpoint /news/topics
Number of subCards : 10
(MsnTagsDataModelTagEntityLibSysTag) Name : outlook-uwp
(MsnTagsDataModelTagEntityLibSysTag) Name : Royals
(MsnTagsDataModelTagEntityLibSysTag) Name : Milwaukee
(MsnTagsDataModelTagEntityLibSysTag) Name : Oklahoma City
(MsnTagsDataModelTagEntityLibSysTag) Name : San Antonio
(MsnTagsDataModelTagEntityLibSysTag) Name : Los Angeles
(MsnTagsDataModelTagEntityLibSysTag) Name : Portland, ME
(MsnTagsDataModelTagEntityLibSysTag) Name : Cleveland
(MsnTagsDataModelTagEntityLibSysTag) Name : New Orleans
(MsnTagsDataModelTagEntityLibSysTag) Name : Baltimore

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Reporting Security Issues

Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) at [email protected]. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the Security TechCenter.

License

Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT license. See Third Party Notices for information on the packages referenced via NuGet.

Dependencies

Microsoft.Rest.ClientRuntime (SDK Project), Newtonsoft.Json (SDK Project), Microsoft.NETCore.App (Sample Project)

msnews-sdk-csharp's People

Contributors

ayigityol avatar dependabot[bot] avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar yigityol-microsoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

msnews-sdk-csharp's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.