ページ

2013年7月29日月曜日

Google API で Bloggerに投稿する際に、ラベル、スケジュール日付を付加する。

Google API で Bloggerに投稿する際に、ラベル、スケジュール日付を付加する。
Google.GData.Clientを参照する。
using Google.GData.Client;
以下がサンプルコード。

schemeに"http://www.blogger.com/atom/ns#" を指定するのが重要なポイントになります。

static AtomEntry PostNewEntry(Service service, Uri blogPostUri
 , string Title, string HtmlContent, DateTime Update
 , string Name, string Email)
{
    Console.WriteLine("\nPublishing a blog post");
    AtomEntry createdEntry = null;
    if (blogPostUri != null)
    {
        // construct the new entry
        AtomEntry newPost = new AtomEntry();
        newPost.Title.Text = Title; //タイトルはダブってもエラーにならない
        newPost.Published = Update;   //日付
        newPost.Content = new AtomContent();
        newPost.Content.Content = HtmlContent;
        newPost.Content.Type = "xhtml";
        newPost.Authors.Add(new AtomPerson());
        newPost.Authors[0].Name = Name;
        newPost.Authors[0].Email = Email;
        newPost.Categories.Add(new AtomCategory(
            "Label1"   //term
            , "http://www.blogger.com/atom/ns#" //scheme
            ));
        try
        {
            createdEntry = service.Insert(blogPostUri, newPost);
            if (createdEntry != null)
            {
                Console.WriteLine("New blog post created);
            }
        }
        catch
        {
        }
    }
    return createdEntry;
}


Service.Insert()でエラーが発生する場合は、HTMLのタグに不整合がないか確認してみよう。

Service.Insertのエラーについて

Service.Insertで発生するエラーについてはいくつか考えられる。

  1. HTMLのタグに不整合
  2. 投稿件数オーバー・セキュリティーロック

HTMLのタグに不整合

いつか使えないタグ、というか古い仕様は受け付けない。
例えば<br>は×、</ br>出ないとだめ。
その他にも対応しないタグが有るようです。

投稿件数オーバー・セキュリティーロック

1日の投稿件数が、ある一定数(?)を超えると、セキュリティーロックが掛かる。
ハッカーが他人のブログをのっとって、ロボットが書き込んでいると判断されるようだ。
手動での各込は出来るが、投稿時にセキュリティ画像に表示される文字の入力が必要になる。
APIではそれが困難である為、エラーが発生する。
セキュリティーロックは翌日になると、解除されるようだが、セキュリティーロックが掛かった日はAPI投稿は中断し、一日に投稿する数を調整する必要がある。
ある一定数(?)というのが分からないが、100投稿もすればセキュリティーロックが掛かるのも当然だと言える。

0 件のコメント:

コメントを投稿