Tweet a URL

  

Hey everyone,

Just wondering if there's an easy way to integrate a twitter "tweet" button without using "Twitter Connector" to share a custom URL? 

For example what can be done with facebook is entering a piece of JS to webscreen's JS property like this 

  window.fbAsyncInit = function() {
    FB.init({
      appId            : 'xxxxxxxx',
      autoLogAppEvents : true,
      xfbml            : true,
      version          : 'v3.1'
    });
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "https://connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

and then using "onclick" extended property on a link with the following piece of code:

"FB.ui({method: 'share',display: 'popup',href: '"+AnyURL+"',}, function(response){});"


Can something similar be done with a twitter? If not, what would be the most simple way to tweet any URL? Can you share some examples?

The most important part is opening the dialog so tweet would contain the info from the URL that I define and not the one I'm tweeting from.
I.E. 

I am on the URL: mysite.com/stepone
The tweet should have URL: mysite.com/steptwo and redirect to it once tweeted.


Thank you!

Hello Marius!

Have you looked into the Twitter for Websites API at https://developer.twitter.com/en/docs/twitter-for-websites/overview?  You can use JavaScript similar to your Facebook example.

Solution

Craig St. Jean wrote:

Hello Marius!

Have you looked into the Twitter for Websites API at https://developer.twitter.com/en/docs/twitter-for-websites/overview?  You can use JavaScript similar to your Facebook example.

Hey Craig,

Thanks for the reply. Yes, I was reading into it. Had problems defining the link I want to share in the dialog box, since I couldn't find the full list of 'data' properties. The solutions is to put this JS piece to a page Javascript property

window.twttr = (function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0],
    t = window.twttr || {};
  if (d.getElementById(id)) return t;
  js = d.createElement(s);
  js.id = id;
  js.src = "https://platform.twitter.com/widgets.js";
  fjs.parentNode.insertBefore(js, fjs);

  t._e = [];
  t.ready = function(f) {
    t._e.push(f);
  };

  return t;
}(document, "script", "twitter-wjs"));

and then define the HTML part something like this

<a class=""twitter-share-button""   href="" https://twitter.com/share""   data-size=""large""   data-text=""custom share text""   data-url="+LinkToShare+"   data-hashtags=""example,demo""   data-via=""twitterdev""   data-related=""twitterapi,twitter""> Tweet</a>

Now the problem is how to customize the button's css, but that is another topic. If by any chance you have any suggestions for that, please let me know.

Thanks a lot!

Solution