2011/08/30
Googleから小包届いた
送り元はGoogle Inc
なんとなく中身は予想できていた。
2010/10/10
Google Buzzの更新APIが来てたのでVimscriptからバズってみた。
Google Buzz API - Google Codeこれはいかん!とばかりにvimscriptから更新してみた。
http://code.google.com/intl/ja/apis/buzz/Share Buzz updates New!
Full read/write support with:
- Activity Streams
- AtomPub
- OAuth
- PubSubHubbub
- JSON
今回の対応で、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-vimAtom APIなのでXMLでポストします。なお、今回GoogleのOAuthを使ったのですが、GoogleのOAuthってドメイン持ってないと使えないんですね。
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
私はここのサイトを使いましたが、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 CodeGoogleのドキュメント通りでは成功しません。実は、このアクセストークン要求先は各サービスによって異なります。ここにアクセスしてもアクセストークン、アクセストークンシークレットは貰えるのですが、これを使ってアクセスしても401が返ります。Google Buzzであれば実際はGoogle Buzz専用の「https://www.google.com/buzz/api/auth/OAuthAuthorizeToken」にアクセスしなければなりません。こちらにはBuzzに対する許可設定画面も出てきます。
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
ここまでくればあとはAtomでXMLを送ればちゃんとBuzzってくれます。![]()
ちなみにココが証拠ポスト。
追記
ちなみに日本語もOKでした。
Tagged as: buzz, google, google buzz, oauth, vim, vimscript
Bookmarks:
|
2010/10/07
Google日本語入力APIを使ってvimでmigemo検索
こんなの migemo の為にあるみたいなもんじゃないですか!
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
さっそく作りました。
"=============================================================================いつも1ファイルで動くものを提供してきましたが、そろそろvimもライブラリとアプリケーションを分けないとvimの今後があやぶまれるな...(vimjoltsってなんだっけ汗)...と思ったので、今回は手前味噌ですが「webapi-vim」というのを使っています。
" 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:
mattn's webapi-vim at master - GitHub先日 vim-oauth で使った奴ですね。
webapi-vim: vim interface to Web APIDescription:Require: curl command : http://curl.haxx.se/Thanks T...
http://github.com/mattn/webapi-vim
まぁ単体にしたい人は書き換えて下さい。
使い方は簡単。
:GogoleMigemo ここではきものをぬぐとすると、「ココでは着物を脱ぐ」がマッチします。なお、「ここでは着物を脱ぐ」が検索したかったよ...という全国2000万人のエロいオッサン達。慌てないで。
:GogoleMigemo ここでは きものを ぬぐとスペースを入れると認識してくれ、ちゃんと「此処では着物を脱ぐ」にマッチします。もちろん「ここで はきものを ぬぐ」とすれば「此処で履物を脱ぐ」や「個々で履物を脱ぐ」にマッチしたりもします。
<leader>mg にキーマップしてあります。あと、グローバル関数「GoogleMigemo」も提供してあるので「let foo = GoogleMigemo(xxx)」な使い方も出来ます。
それなりに便利かもしれません。もちろんネットに繋がってないと使えませんし、エロい語句を検索すると、Google先生にネタを送ってしまいます。
ご利用は計画的に。
2010/01/28
Googleサジェストから補完候補を作るVimスクリプト書いた。
芸能人の名前辞書用意持ってる人なんて見たことないですね。たいがいこういう時はGoogle先生にたよるのが一般的です。
今日はGoogleサジェスト(Google検索で数文字打ったら出てくるあの候補)からvimの補完を行えるスクリプトを書いてみました。
例えばこんな事が出来ます。
おもむろに「takasu」と打って、<c-x><c-u>とタイプします。![]()
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




![Validate my RSS feed [Valid RSS]](http://mattn.kaoriya.net/images/valid-rss-rogers.png)

