5

Here is the Blogger's API v3 page : https://developers.google.com/blogger/docs/3.0/using

and downloaded the NuGet Blogger API packages : https://www.nuget.org/packages/Google.Apis.blogger.v2

My developing environment is Visual Studio 2010 with C# language

How can i use the Blogger's API?

I just can't understand what they wrote in https://developers.google.com/resources/api-libraries/documentation/blogger/v3/csharp/latest/namespaces.html ...

How to initialize a new Blogger Service and get a list of all the posts?

Where to auth with my application (the ClientID and ClientSecret)?

4

3 回答 3

2

您需要 GDATA 客户端,为此您需要下载 Google API。在这里下载。您需要安装该 MSI,它将向您的系统添加 dll、示例。

C:\Program Files\Google\Google 数据 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);
于 2013-10-13T15:33:22.697 回答
2

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

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

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

用以下代码替换您的 Main 代码:

    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}");
            }
        }
    }
于 2020-05-21T14:39:32.580 回答
-1

首先,您必须从以下链接安装 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这个链接中没有代码

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

于 2015-07-21T09:41:16.123 回答