davidbauer / Instacurate

Turn your Twitter timeline into a personalised news site, in an instant. Fetches links from your timeline and displays them in a discovery friendly design.
http://www.instacurate.com
113 stars 29 forks source link

Display corresponding tweet to a link in a tooltip #13

Closed davidbauer closed 11 years ago

davidbauer commented 11 years ago

most code needed for this is added. however tweetId is undefined when used by generateTweetEmbed(). looks like a scope-problem, but I can't figure out what to change. probably have to add a return tweetId somewhere, but where? @dergraf, @backflip

backflip commented 11 years ago

generateTweetEmbed()is called inside generateEmbed()which has no knowledge of tweeId. You could add this variable as a third parameter to generateEmbed() when calling it inside getLinks().

backflip commented 11 years ago

Addendum: When declaring variables without var (like tweetembed in generateTweetEmbed()), they end up in the window's scope, which is usually not the desired outcome.

davidbauer commented 11 years ago

Implemented it as suggested (at least I think so), still doesn't work, though. What am I missing?

backflip commented 11 years ago

I get 404s on the API calls in generateTweetEmbed.

davidbauer commented 11 years ago

Hm. Updated the url to Twitter API 1.1., didn't help. What else could be the cause? https://dev.twitter.com/docs/api/1.1/get/statuses/oembed

backflip commented 11 years ago

Looks like you have to use tweet.id_str instead of tweet.id.

dergraf commented 11 years ago

manually requesting e.g. https://api.twitter.com/1.1/statuses/oembed.json?id=286411720862351360 responds with {"errors":[{"message":"Bad Authentication data","code":215}]} maybe related?

davidbauer commented 11 years ago

tweet.id_str doesn't do the trick.

backflip commented 11 years ago

Depends on what you are testing. I got rid of the 404s using tweet.id_str. However, I'm not sure whether you can use an AJAX request to generate the tooltip content (since there is no immediate return value of generateTweetEmbed()). I'd suggest to init the tooltip as a callback:

function initTooltip(tweetId, $tweet) {
    $.getJSON('https://api.twitter.com/1/statuses/oembed.json?id=' + tweetId + '&callback=?', function(embed) {
        $tweet.tooltip({ content: embed.html });
    });
}
backflip commented 11 years ago

@dergraf I guess that ID is wrong (although that should return a different message). But I'm receiving a "Rate limit exceeded" anyway. Twitter API FTW...

Addendum: 1.1 does not support this syntax anymore: http://stackoverflow.com/questions/12684765/twitter-api-returns-error-215-bad-authentication-data

dergraf commented 11 years ago

me too.

one thing noticed: $( ".tweet" ).tooltip({ content: generateTweetEmbed(tweetId) }) cannot work since we always override the tooltips. It's better to add an id to the tooltip div and operate on that id, at least we should be able to get some proper tooltips.

backflip commented 11 years ago

We are already caching the specific link element (or it's parent, respectively) using $tweet, that should be enough.

backflip commented 11 years ago

Whoups, I guess my function should be the following, since $tweet is the container of the link:

function initTooltip(tweetId, $tweet) {
    $.getJSON('https://api.twitter.com/1/statuses/oembed.json?id=' + tweetId + '&callback=?', function(embed) {
        $tweet.find('a').tooltip({ content: embed.html });
    });
}
backflip commented 11 years ago

I would add the tooltip to the link instead of the container. Otherwise it's not positioned correctly und the hover area is too wide.

dergraf commented 11 years ago

agree, can you do that?

backflip commented 11 years ago

Ok, I will do it tomorrow. If I figure out how to do a pull request... :flushed:

dergraf commented 11 years ago

no worries it's not difficult. just fork the repo make your changes, commit and push. Back on Github you have a button for making a pull request. Am 04.01.2013 00:03 schrieb "Thomas Jaggi" notifications@github.com:

Ok, I will do it tomorrow. If I figure out how to do a pull request... [image: :flushed:]

— Reply to this email directly or view it on GitHubhttps://github.com/davidbauer/Twitter-Times/issues/13#issuecomment-11865107.

backflip commented 11 years ago

Perfect, sounds feasible. And it's about time, I suppose.