WeiboFocus
interfaces for sina weibo on oauth2
Installation
Add this line to your application's Gemfile:
gem 'weibo_focus'
And then execute:
$ bundle
Or install it yourself as:
$ gem install weibo_focus
Usage
config/weibo.yml 在新浪应用设置授权回调地址与redirect_uri相同
development:
api_key: your-api-key
api_secret: your-api-secret
redirect_uri: "http://192.168.184.16:3000/home/callback"
controller
def callback
client = Weibo::Client.new
access_token = client.auth_code.get_token(params[:code].to_s)
session[:uid] = access_token.params["uid"]
session[:access_token] = access_token.token
session[:expires_at] = access_token.expires_at
if user_signed_in?
#把相关信息存入数据库
save_user_key(current_user.id,session[:access_token], session[:expires_at], session[:uid])
end
redirect_to "/home/index"
end
def connect
client = Weibo::Client.new
redirect_to client.
end
方法调用
client = Weibo::Client.new
client.接口名.方法名(参数详看新浪api)[http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2]
例如:获取当前登录用户及其所关注用户的最新微博
@client.statuses.friends_timeline
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Error
OAuth2::Error (Sorry, that page doesn’t exist!)---without .json
error:
get("tags/suggestions", :params => opt)
ok:
get("tags/suggestions.json", :params => opt)