SocialPoster is a jam that makes it easy to post to popular social networks from your Ruby apps. Currently there is support for such networks:
- Facebook
- Twitter
- Livejournal
- Vkontakte
You can install the
gem with the
gem install social_poster command or use the Bundler to do this.
Customization
This jam can work with or without Rails. Here I will give an example of how to set up and use the social_poster in a Ruby on Rails application. First, you need to create a config file config / initializers / social_poster.rb with the following contents:
SocialPoster.setup do |config| config.fb = { access_token: 'ACCESS_TOKEN' } config.vk = { access_token: 'ACCESS_TOKEN' } config.twitter = { consumer_key: 'CONSUMER_KEY', consumer_secret: 'CONSUMER_SECRET', oauth_token: 'OAUTH_TOKEN', oauth_token_secret: 'OAUTH_TOKEN_SECRET' } config.lj = { user: 'USER', password: 'PASSWORD' } end
You need to fill in the values ​​for keys, logins and passwords (depending on the requirements of these sites).
Using
Now in the model or in the controller, you can post to various social networks, simply by pointing out her name and the text to be placed:
')
SocialPoster.write(:fb, 'Something that will appear on your Facebook Wall...') SocialPoster.write(:vk, 'Something that will appear on your Vkontakte Wall...') SocialPoster.write(:twitter, 'Tweet tweet tweet') SocialPoster.write(:lj, 'A long text of the post...', 'A short title of it')
For API Vkontakte, it is possible to set additional options. Here, for example, how to post to a group:
SocialPoster.write(:vk, 'Text on the Group Wall...', nil, owner_id: '-GROUP_ID')
You can also set advanced options when posting to Facebook. Here is an example for placing photos and links on the wall:
SocialPoster.write(:fb, 'Text on the Wall...', nil, link: 'http://google.com', picture: 'https://www.google.com/images/srpr/logo11w.png')