开发者

Sharing articles on Facebook using the facebook api

I have a rails application that helps users submit articles. Does any one know how I can make users in the开发者_如何学运维 application share those articles on facebook using their facebook address? A good reference or tutorial would be good.


You can open a popup to http://www.facebook.com/sharer.php?u=URL. This will display a share on facebook page with a link to your image.

For example: http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.google.com


Here is the ruby on rails syntax for it:

<%= link_to image_tag('/images/FaceBookIcon.png'), 'http://www.facebook.com/sharer.php?u='+request.fullpath, :target => :blank %>


The "sharer" link has been deprecated. Check out the updated documentation here:

https://developers.facebook.com/docs/reference/dialogs/feed/

A simple example using the Direct URL approach in Rails looks like this:

<%= link_to('Share on Facebook', 'https://www.facebook.com/dialog/feed?
                                  link=https://developers.facebook.com/docs/reference/dialogs/&
                                  picture=http://fbrell.com/f8.jpg&
                                  name=Facebook%20Dialogs&
                                  caption=Reference%20Documentation&
                                  description=Using%20Dialogs%20to%20interact%20with%20users.&
                                  redirect_uri=https://mighty-lowlands-6381.herokuapp.com/',
                                  :target => :blank %>


i found out a trick for sharing to facebook with Oauth token here is my link

parameters were broken with line breaks to make them more readable

<a target="_blank" 
   href="https://www.facebook.com/dialog/feed
     ?app_id=134530986736267
     &link=<%= request.original_url %>
     &name=<%= @article.title%>
     &picture=<%=image_url(@article.image)%>
     &redirect_uri=http://facebook.com/" 
   class="icon icon-facebook">
</a>

Source : http://bechirsegni.me/articles/how-to-share-articles-on-facebook-without-oauth-access-token


I had to piece together a few answers to arrive at a working solution.

You can include this in the bottom of your Article show page:

<%= link_to "https://www.facebook.com/sharer/sharer.php?u=#{article_url(@article)}",  title: 'Share Me!' do %>
<i class="huge facebook icon" data-content="Share Me!"></i>
<% end %>

It's also worth noting that the Facebook page that opens as result of this button being clicked should probably also be aware of the title of the article, and maybe a snippet of its text, or a description. You can set the title of the page using this: Rails 3 - Ideal way to set title of pages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜