SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    790
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    more questions on parsing Twitter Feeds...


    hi,

    I found these really neat functions for parsing links, hashtags and unsernames in twitter feeds (i.e., convert them to links.... why on earth don't they come in as links already?????..... ;-o)

    but now I'm trying to "get cute" and give the different links (regular links, usernames, hastags) different font colors (would love to find a way to add an "addClass" functionality to those parsing functions...;-) so came up with my own funky code, and needless to say, am running into problems.. either it works and only one record prints, or I move this block of code somewhere else, and then all records print again, but font color doesn't change...

    my entire code, with comments explaining problems (which are numerous):

    Code:
    //	********** set font color for the links -- PROBLEMS ARE HERE.........
    	$('#results a').each(function(i) {
    	//	$(this).css('color','green'); // this test line sets font color for all links except tweet url (??)
    		
    		var hrefAttr = $(this).attr('href');
    		console.log('hrefAttr -- ' + hrefAttr);	//	prints fine, but on below line get 'undefined' (???)
    	//	if link is hashtag link	
    	//	********* GET ERROR 'undefined' ON BOTH THESE TWO LINES (???) ********
    		if ( $(this).attr('href').indexOf('/search?q=') != -1) {
    	//	if ( hrefAttr.indexOf('/search?q=') != -1) {
    			$(this).addClass('linkHTag'); // works, but only one record prints..  if I comment out 
    										// this entire font-color block then all records print...(????)
    										// tried putting this block outside $.each method, then  
    										//	it prints all records, but the font colors don't change...
    		}
    		
    		//	if link is user link
    		/*	if (hrefAttr.indexOf('/search?q=') == -1 && hrefAttr.indexOf('/t.co/') == -1 && hrefAttr.indexOf('/status/') == -1) {
    				$(this).addClass('linkUser');	//	doesn't work at all....
    			}
    		});   
    	*/
    	
    	});
    I hope this is enough to glean problem... (this code is inside $.each fn where I parse the data (right after I print the content with .html() method..) just in case, entire .js is here...)

    thank you.....


  2. #2
    Barefoot on the Moon! silver trophy
    Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,516
    Mentioned
    51 Post(s)
    Tagged
    1 Thread(s)
    As a side note, libraries for accessing Twitter data already exist. Have you had a look at those?

    https://dev.twitter.com/docs/twitter-libraries

    Parsing HTML output can be tricky as it can change without warning.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •