Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

ruby on rails - Easy way of posting on Facebook page (not a profile but a fanpage)

Which option is the best and easy way to post text or some other content on a Facebook page?

I'm looking for a direct way to put something there from my Rails application.

For instance, clicking on a button and automatically posting on my application and sending data to the facebook page?

I've built one for Twitter and the method I have looks like this:

def tweet(url)
  Twitter.configure do |config|
    config.consumer_key = APP_CONFIG['twitter_consumer_key']
    config.consumer_secret = APP_CONFIG['twitter_consumer_secret']
    config.oauth_token = APP_CONFIG['twitter_access_token']
    config.oauth_token_secret = APP_CONFIG['twitter_secret_token']
  end    
  shorted_url = shorten_url(url)
  Twitter.update("#{title} - #{shorted_url}")
end

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can follow this link What's the easiest way, to post on my Facebook Wall through my Ruby on Rails App?

this is how my method look like:

def facebook_it(url)
  pages = FbGraph::User.me(APP_CONFIG['facebook_access_token']).accounts.first
  shorten_url = shorten_url(url) # create a bit.ly link
  pages.feed!(
    :message => "#{title}",
    :link => shorten_url,
    :description => "#{content[0..280]}"
  )
end

also I've created another method:

def share(url)
  tweet(url)
  facebook_it(url)
end

so I call it this way from the controller:

def publish
  url = job_url(@job)
  @job = Job.find(params[:id])
  @job.publish
  @job.share(url)
  ..
end

I don't know if this is the better approach, but it's working nice for me.

Hope this helps someone else.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...