【问题标题】:How to use Blogger API v3如何使用 Blogger API v3
【发布时间】:2013-10-15 04:42:23
【问题描述】:

这是 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)?

【问题讨论】:

    标签: c# api blogger


    【解决方案1】:

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

    C:\Program Files\Google\Google 数据 API SDK

    1. 将Google.GData.Blogger.dll 添加到您的项目中
    2. 添加引用后,可以使用这个link作为引用。

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

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

    【讨论】:

    • @GaryNg:我怀疑。那它有什么用呢?我最近使用 API 3 开发了实用程序,我肯定使用了 Google.GData.Blogger.dll 。我在这里错过了什么吗?
    • 您的代码在过去 10 个月之前使用过,但现在已更改
    • OP 要求使用 API KEY。
    【解决方案2】:

    这是一个现代 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}");
                }
            }
        }
    

    【讨论】:

      【解决方案3】:

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

      目前我正在处理这个,它不会来..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多