如何使用 Blogger API v3

本文关键字:v3 API Blogger 何使用 | 更新日期: 2023-09-27 18:34:34

这是博主的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

如何使用博主的 API?

我只是无法理解他们在 https://developers.google.com/resources/api-libraries/documentation/blogger/v3/csharp/latest/namespaces.html 上写了什么......

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

在哪里对我的应用程序(客户端 ID 和客户端密钥(进行身份验证?

如何使用 Blogger API v3

您需要GDATA客户端,为此您需要下载Google API。在此处下载。您需要安装该MSI,它会将dll,示例添加到您的系统中。

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

  1. 向项目添加Google.GData.Blogger.dll
  2. 添加引用后,可以使用此链接作为参考。

以下代码可用于创建服务和从 Blogger 获取数据。

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

这是一个现代 C# 示例解决方案,用于在控制台应用中使用 API KEY 访问 Blogger v3 API。

创建一个新的 .NET 框架控制台应用项目。

安装以下 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}");
            }
        }
    }

从以下链接安装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 没有代码

目前我正在研究这个,它不会来..