卒論で3年次に作ったtalklineという奴も取り扱うことになったのでちょこっと修正しました
twitterにbitlyで短縮したURL付きのpostが出来るように
oauthについては参考サイト多数なので省略
良くわからなかったのはoauthの認証情報でどれを保存すれば良いのか?
保存するのはaccess_tokenとaccess_token_secretでした
この2つを保存しておけば以後consumerキーと組み合わせて即リクエスト出来ます
bitly対応では
Rubyでbit.lyのAPI経由で短縮URLを取得する - 黒川仁の文具堂ブログ三昧
APIを取得してこちらのshortenメソッドをコピペしました
例のごとく反映は遅れるかも
oauth, twitter
先日、twitterが正式に位置情報に対応しましたが、自分も試してみました
rubyのtwitterというgemでやってみました
RUBY:
-
# access_token, access_token_secretはあらかじめ準備しているものとします
-
twitter_oauth = Twitter::OAuth.new(CONSUMER_KEY, SECRET_KEY)
-
twitter_oauth.authorize_from_access(
-
access_token, access_token_secret)
-
@twitter = Twitter::Base.new(twitter_oauth)
-
@twitter.update('hoge', {:lat => latitude, :long => longtitude})
こんな感じでoptionを渡してやるだけです
twitter_gemのドキュメントにはoptionがin_reply_to_status_idしか書いてないのですが、ちゃんと投稿してくれます
ちなみに埋め込んだ座標をtweetdeckで表示するとこんな感じ

NY maps overlay on tweetdeck
geolocation, ruby, twitter
verify_credentialsメソッドは認証したユーザについての情報を返す
Mashとかいうhashっぽいので定義されていて、何故かメソッドのごとく" . "でアクセス出来る
例)Twitter::Base.new(oauth).verify_credentials.screen_name
RUBY:
-
created_at
-
description
-
favorited
-
favourites_count
-
followers_count
-
following
-
friends_count
-
geo_enabled
-
href
-
id
-
in_reply_to_screen_name
-
in_reply_to_status_id
-
in_reply_to_user_id
-
location
-
name
-
notifications
-
profile_background_color
-
profile_background_image_url
-
profile_background_tile
-
profile_image_url
-
profile_link_color
-
profile_sidebar_border_color
-
profile_sidebar_fill_color
-
profile_text_color
-
protected
-
rel
-
screen_name
-
source
-
status
-
statuses_count
-
text
-
time_zone
-
truncated
-
url
-
utc_offset
-
verified
ruby, twitter
#追記
原因は良く分からないけど、なんかいつの間にか出来るようになってた
#追記終了
サンプルを漁ると大体:oauth_callbackがスクリプト側で上書きされているけど、
最近は仕様が変わったのかそれだとUnauthorizedが返ってくるみたい
web上で行う設定とスクリプト側の指定を同じにする必要があるらしい
でもweb上の設定だとlocalhostとか指定出来ないし、一度どこかにアップロードしないとテストも出来なくて面倒
developmentモードとか用意して欲しいなー
#google.comとかも指定出来ない???
#なんか良くわからん…
twitter