Fork me on GitHub

2011/08/30


このエントリーをはてなブックマークに追加
先日、庭で子供のプールを汗だくになりながら膨らませ、子供に本気で水をかけられずぶ濡れ状態だった中、ちょっと大きめの郵便が届いた。
送り元はGoogle Inc

なんとなく中身は予想できていた。

続きを読む...

Posted at 01:10 in その他
Tagged as: golang, google
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2010/10/10


このエントリーをはてなブックマークに追加
以前まではreadonlyなAPIでしたが、先日見たら更新出来る様になってた。
Google Buzz API - Google Code

Share Buzz updates New!

Full read/write support with:
  • Activity Streams
  • AtomPub
  • OAuth
  • PubSubHubbub
  • JSON

http://code.google.com/intl/ja/apis/buzz/
これはいかん!とばかりにvimscriptから更新してみた。

今回の対応で、vim-oauth(現在webapi-vimに取り込まれました)に幾らか修正をしました。
mattn's webapi-vim at master - GitHub

webapi-vim: vim interface to Web API

http://github.com/mattn/webapi-vim
以下、使用したスクリプト。
set rtp+=webapi-vim

let request_token_url = "https://www.google.com/accounts/OAuthGetRequestToken"
let access_token_url = "https://www.google.com/accounts/OAuthGetAccessToken"
let auth_url = "https://www.google.com/buzz/api/auth/OAuthAuthorizeToken"
let post_url = "https://www.googleapis.com/buzz/v1/activities/@me/@self"

let consumer_key = $CONSUMER_KEY
let consumer_secret = $CONSUMER_SECRET
let domain = $CONSUMER_DOMAIN
let callback = $CONSUMER_CALLBACK

let [request_token, request_token_secret] = oauth#requestToken(request_token_url, consumer_key, consumer_secret, {"scope": "https://www.googleapis.com/auth/buzz", "oauth_callback": callback})
if has("win32") || has("win64")
  exe "!start rundll32 url.dll,FileProtocolHandler ".auth_url."?oauth_token=".request_token."&domain=".domain."&scope=https://www.googleapis.com/auth/buzz"
else
  call system("xdg-open '".auth_url."?oauth_token=".request_token."'")
endif
let verifier = input("PIN:")
let [access_token, access_token_secret] = oauth#accessToken(access_token_url, consumer_key, consumer_secret, request_token, request_token_secret, {"oauth_verifier": verifier})
echo access_token
echo access_token_secret
let data = ''
\.'<entry xmlns:activity="http://activitystrea.ms/spec/1.0/"'
\.' xmlns:poco="http://portablecontacts.net/ns/1.0"'
\.' xmlns:georss="http://www.georss.org/georss"'
\.' xmlns:buzz="http://schemas.google.com/buzz/2010">'
\.'  <activity:object>'
\.'    <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>'
\.'    <content>Bzz! Bzz!</content>'
\.'  </activity:object>'
\.'</entry>'
let ret = oauth#post(post_url, consumer_key, consumer_secret, access_token, access_token_secret, {}, data, {"Content-Type": "application/atom+xml", "GData-Version": "2.0"})
echo ret
Atom APIなのでXMLでポストします。なお、今回GoogleのOAuthを使ったのですが、GoogleのOAuthってドメイン持ってないと使えないんですね。
私はここのサイトを使いましたが、Google App EngineでもOKです。

まずココでドメインを登録します。実はこのドメイン名がconsumer_keyとなります。ドメインを登録するとconsumer_secretが貰えます。
またコールバック先のURLが必要になります。通常登録したドメイン上でもよいのですが、別のサイトでも構わない様です。さらにGoogle OAuthではリクエストトークンを取得する際、およびベリファイアを貰う際にscopeパラメータが必要です。個々のGoogleサービスによって異なりますので、ココの一覧を参照して設定して下さい。なお、Google Buzzについてはリストアップされていませんが、色々探して見つけました。
さて次にアクセストークンを取得するのですが、ここで気をつけないとハマる問題がありあます。
Authentication in the Google Data Protocol - Google Data Protocol - Google Code

https://www.google.com/accounts/OAuthAuthorizeToken, referencing the request token and including the oauth_callback parameter. Google may prompt the user to log into their Google Account. Once authenticated with Google, the user chooses to share their data.

http://code.google.com/intl/ja/apis/gdata/docs/auth/overview.html
Googleのドキュメント通りでは成功しません。実は、このアクセストークン要求先は各サービスによって異なります。ここにアクセスしてもアクセストークン、アクセストークンシークレットは貰えるのですが、これを使ってアクセスしても401が返ります。Google Buzzであれば実際はGoogle Buzz専用の「https://www.google.com/buzz/api/auth/OAuthAuthorizeToken」にアクセスしなければなりません。こちらにはBuzzに対する許可設定画面も出てきます。
google-buzz-api1
ここまでくればあとはAtomでXMLを送ればちゃんとBuzzってくれます。

ちなみにココが証拠ポスト。

追記
ちなみに日本語もOKでした。
Posted at 02:02 in ソフトウェア::vim
Tagged as: buzz, google, google buzz, oauth, vim, vimscript
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2010/10/07


このエントリーをはてなブックマークに追加
先日「Google 日本語入力 - CGI API」が公開されましたね。
Google 日本語入力 - CGI API
Google 日本語入力 - CGI API デベロッパーガイド

Google CGI API for Japanese Input Google CGI API for Japanese Input は、日本語変換をインターネット上で実現するための、CGI サービ...

http://www.google.com/intl/ja/ime/cgiapi.html
こんなの migemo の為にあるみたいなもんじゃないですか!

さっそく作りました。
"=============================================================================
" File: gmigemo.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change:08-Oct-2010.
" Version: 0.1
" WebPage: http://github.com/mattn/gmigemo-vim
" Usage:
"
"   :GoogleMigemo ここではきものをぬぐ
"     match: "ココでは着物を脱ぐ"
"
"   :GoogleMigemo ここで はきものを ぬぐ
"     match: "此処で履物を脱ぐ"
"
" Require:
"   webapi-vim: http://github.com/mattn/webapi-vim

if exists("loaded_gmigemo") || v:version < 700
  finish
endif
let loaded_gmigemo = 1

function! s:nr2byte(nr)
  if a:nr < 0x80
    return nr2char(a:nr)
  elseif a:nr < 0x800
    return nr2char(a:nr/64+192).nr2char(a:nr%64+128)
  else
    return nr2char(a:nr/4096%16+224).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128)
  endif
endfunction

function! s:nr2enc_char(charcode)
  if &encoding == 'utf-8'
    return nr2char(a:charcode)
  endif
  let char = s:nr2byte(a:charcode)
  if strlen(char) > 1
    let char = strtrans(iconv(char, 'utf-8', &encoding))
  endif
  return char
endfunction

function! g:GoogleMigemo(word)
  let word = substitute(a:word, '\s', ',', 'g')
  let url = "http://www.google.com/transliterate"
  let res = http#get(url, { "langpair": "ja-Hira|ja", "text": word }, {})
  let str = iconv(res.content, "utf-8", &encoding)
  let str = substitute(str, '\\u\(\x\x\x\x\)', '\=s:nr2enc_char("0x".submatch(1))', 'g')
  let str = substitute(str, "\n", "", "g")
  let g:hoge = str
  let arr = eval(str)
  let mx = ''
  for m in arr
    call map(m[1], 'substitute(v:val,"\\\\", "\\\\\\\\", "g")')
    let mx .= '\('.join(m[1], '\|').'\)'
  endfor
  return mx
endfunction

function! s:GoogleMigemo(word)
  if executable('curl') == 0
    echohl ErrorMsg
    echo 'GoogleMigemo: curl is not installed'
    echohl None
    return
  endif

  let word = a:word != '' ? a:word : input('GoogleMigemo:')
  if word == ''
    return
  endif
  let mx = g:GoogleMigemo(word)
  let @/ = mx
  let v:errmsg = ''
  silent! normal n
  if v:errmsg != ''
    echohl ErrorMsg
    echo v:errmsg
    echohl None
  endif
endfunction

command! -nargs=* GoogleMigemo :call <SID>GoogleMigemo(<q-args>)
nnoremap <silent> <leader>mg :call <SID>GoogleMigemo('')<cr>

" vi:set ts=8 sts=2 sw=2 tw=0:
いつも1ファイルで動くものを提供してきましたが、そろそろvimもライブラリとアプリケーションを分けないとvimの今後があやぶまれるな...(vimjoltsってなんだっけ汗)...と思ったので、今回は手前味噌ですが「webapi-vim」というのを使っています。
mattn's webapi-vim at master - GitHub

webapi-vim: vim interface to Web APIDescription:Require: curl command : http://curl.haxx.se/Thanks T...

http://github.com/mattn/webapi-vim
先日 vim-oauth で使った奴ですね。
まぁ単体にしたい人は書き換えて下さい。

使い方は簡単。
:GogoleMigemo ここではきものをぬぐ
とすると、「ココでは着物を脱ぐ」がマッチします。なお、「ここでは着物を脱ぐ」が検索したかったよ...という全国2000万人のエロいオッサン達。慌てないで。
:GogoleMigemo ここでは きものを ぬぐ
とスペースを入れると認識してくれ、ちゃんと「此処では着物を脱ぐ」にマッチします。もちろん「ここで はきものを ぬぐ」とすれば「此処で履物を脱ぐ」や「個々で履物を脱ぐ」にマッチしたりもします。
<leader>mg にキーマップしてあります。あと、グローバル関数「GoogleMigemo」も提供してあるので「let foo = GoogleMigemo(xxx)」な使い方も出来ます。
それなりに便利かもしれません。もちろんネットに繋がってないと使えませんし、エロい語句を検索すると、Google先生にネタを送ってしまいます。
ご利用は計画的に。
Posted at 23:29 in ソフトウェア::vim
Tagged as: google, IME, migemo
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip

2010/01/28


このエントリーをはてなブックマークに追加
vimの入力補完って大変便利なんですが、例えば「あーあの芸能人、名前分かるけどどの漢字だったっけ...」なんて事がたまにあります。
芸能人の名前辞書用意持ってる人なんて見たことないですね。たいがいこういう時はGoogle先生にたよるのが一般的です。
今日はGoogleサジェスト(Google検索で数文字打ったら出てくるあの候補)からvimの補完を行えるスクリプトを書いてみました。

例えばこんな事が出来ます。
googlesuggest-complete-vim1
おもむろに「takasu」と打って、<c-x><c-u>とタイプします。
googlesuggest-complete-vim2

Yes! 高須クリニック!


えっ2番?...うるさい!

便利ですね!

また「watasinonamaeha」(私の名前は)と打って<c-x><c-u>すると...
私の名前はキムサムスン
誰ですか!キムサムスン!

例えば「naitu」なら...
ナイツ お笑い
「www」なら...
www.yahoo.co.jp
「gm」だけで...
gmailへようこそ
... えっ ...

びっ...「vimp」ならば...
vimperator
そして「puri」で...
プリキュア

便利過ぎます!

もうIMEいりません!

どうかお役立て下さい!
mattn's googlesuggest-complete-vim at master - GitHub

complete function using google suggest API. perhaps, you should input japanese without IME.

http://github.com/mattn/googlesuggest-complete-vim
Posted at 23:13 in ソフトウェア::vim
Tagged as: google, vim
Bookmarks: add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip