如何使用Blogger API v3

时间:2013-10-08 10:00:51

标签: c# api blogger

以下是Blogger的API v3页面:https://developers.google.com/blogger/docs/3.0/using

并下载了NuGet Blogger API包:https://www.nuget.org/packages/Google.Apis.blogger.v2

我的开发环境是带有C#语言的Visual Studio 2010

我如何使用Blogger的API?

我无法理解他们在https://developers.google.com/resources/api-libraries/documentation/blogger/v3/csharp/latest/namespaces.html ...

中所写的内容

如何初始化新的Blogger服务并获取所有帖子的列表?

使用我的应用程序(ClientID和ClientSecret)进行身份验证的位置?

3 个答案:

答案 0 :(得分:3)

您需要GDATA客户端,因此您需要下载Google API。 下载here。您需要安装该MSI,它会将dll,samples添加到您的系统中。

  

C:\ Program Files \ Google \ Google Data API SDK

  1. Google.GData.Blogger.dll添加到您的项目
  2. 添加引用后,您可以使用此link作为参考。
  3. 以下代码可用于创建服务和从Blogger获取数据。

    Service service = new Service("blogger", "blogger-example");
    string username = "abc@gmail.com";
    string password = "abc143";
    service.Credentials = new GDataCredentials(username, password);
    

答案 1 :(得分:0)

您必须从下面的链接安装Blogger的API v3 您是为API V2安装的

https://www.nuget.org/packages/Google.Apis.Blogger.v3/

https://developers.google.com/resources/api-libraries/documentation/blogger/v3/csharp/latest/namespaces.html此链接中没有代码

目前我正在研究这个问题,它还没有来......

答案 2 :(得分:0)

这是现代的C#示例解决方案,可通过控制台应用程序中的API KEY访问Blogger v3 API。

创建一个新的.NET Framework控制台应用程序项目。

安装以下NuGet软件包:https://www.nuget.org/packages/Google.Apis.Blogger.v3/

将主代码替换为以下代码:

    static void Main(string[] args)
    {
        Console.WriteLine("Blogger API Sample");
        Console.WriteLine("==================");

        CancellationTokenSource cts = new CancellationTokenSource();

        System.Console.CancelKeyPress += (s, e) =>
        {
            e.Cancel = true;
            cts.Cancel();
        };

        try
        {
            MainAsync(args, cts.Token).Wait();
        }
        catch (AggregateException ex)
        {
            foreach (var e in ex.InnerExceptions)
            {
                Console.WriteLine("EXCEPTION: " + e.Message);
            }
        }

        Console.WriteLine("Press any key to continue...");
        Console.ReadKey();
    }

    static async Task MainAsync(string[] args, CancellationToken ct)
    {
        if (args == null || args.Length != 1) args = new string[] { "http://blogger.googleblog.com/" };

        // Create the service.
        BloggerService service = new BloggerService(new BaseClientService.Initializer
        {
            ApplicationName = "Your Blogger App Name Here",
            ApiKey = "[YOUR_API_KEY_HERE]",
        });

        // Run the blog request.
        Console.WriteLine($"Executing blog {url} request...");
        var blogResult = await service.Blogs.GetByUrl(url).ExecuteAsync(ct);

        // Display the results.
        if (blogResult.Posts != null)
        {
            //Run the posts request
            Console.WriteLine($"Executing posts {blogResult.Posts.SelfLink} request...");
            var postsResult = await service.Posts.List(blogResult.Id).ExecuteAsync(ct);

            foreach (var post in postsResult.Items)
            {
                Console.WriteLine($"{post.Id} - {post.Title}");
            }
        }
    }