Javascript events return undefined


#1

Hello,

I try to get some information about the twitter user when he clicks on tweet button (like user_id or screen_name). For test purpose I add a simple tweet button on an html page and some javascript code as I described below :

This is the code to get information on tweet event :

<script type="text/javascript">
  twttr.ready(function (twttr) {
    function handleTweetEvent(event){
      if (event.data) {
        alert(event.data.tweet_id+' '+event.data.source_tweet_id+' '+event.data.screen_name+' '+event.data.user_id);
      }
    }
    twttr.events.bind('tweet', handleTweetEvent);
});
</script>

But my javascript alert renders : “undefined undefined undefined undefined”.

My tweet button looks like this :

<a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>

And according to this part of the documentation : https://dev.twitter.com/docs/intents/events, I added this snippet in the head section of my html page :

<script type="text/javascript" charset="utf-8">
  window.twttr = (function (d,s,id) {
    var t, js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
    js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
    return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
  }(document, "script", "twitter-wjs"));
</script>

I don’t understand why all attributes are “undefined” ? Do you have an idea about this problem?
Thanks a lot for your help.


#2

User information is not available from the Tweet web intent as it would identify the user who is currently on your site. Tweet Button events mostly pertain to the DOM element clicked and whether the action was completed or not.


#3

Thanks for your answer. Is there another way to know the user_id when a tweet is complete? I can imagine when a tweet is complete the user is identified on twitter plateform, therefore may be we can get this information?


#4

It’s kind of missing on purpose – the user doesn’t have a relationship (modeled by an OAuth connection in our platform) with the site, so doesn’t have the opportunity to be asked whether it’s all right to share their information with you.

For public tweets, you can use the Search API or Streaming API to monitor tweets mentioning your URLs and domains.


#5

You’re completely right. I perform some test on a same html page of the same domain … so … I mixed up client side and server side.
Again, thanks for your answer.


#6