开发者

tweet this link in rails app

开发者 https://www.devze.com 2023-01-09 19:30 出处:网络
I am surprised I couldn\'t find it on google, what\'s the best way to add a \"tweet\" this link to post a url and a description to the user\'s twitter ac开发者_如何学Pythoncount?The \'tweet this link\

I am surprised I couldn't find it on google, what's the best way to add a "tweet" this link to post a url and a description to the user's twitter ac开发者_如何学Pythoncount?


The 'tweet this link' feature is extremly simple and does not require additional Rails features. It is as simple as:

<a href=http://twitter.com/home?status=Name_and_Address_of_the_twitter_post_that_you_want_everyone to_see_on_twitter>Add to Twitter</a>

To use Rails code, it would be something like:

= link_to "tweet me", "http://twitter.com/home?status=#{@post.short_name} #{post_url(@post)}"

Some remarks:

  • the status should not be bigger than 140 chars (you can use either an external service as bit.ly or you can write your own controller that answers to small addresses and that redirects to the post)

  • you can also implement a tracking mechanism that could detect how many users clicked on the 'tweet this' link


The accepted answer used to work for me, but it stopped at some point. A link like this is now working for me:

https://twitter.com/intent/tweet?text=Some%20description&url=https://example.com/someurl
0

精彩评论

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