Showing posts with label Counting Comments. Show all posts
Showing posts with label Counting Comments. Show all posts

Nov 12, 2009

Blogger API Limitations :(




Well folks, it deeply saddens me to announce that the blog and comment counter I spent so much time and brain power on is not going to remain useful very much longer! :( Apparently the Blogger API has a limit of 200 entries, and that's why the comments are being counted incorrectly already. Our class has a total of 130 blog posts so far, and if that surpasses 200, the count will begin to be incorrect as the comments counting is. I wish there was something I could do, but I guess we'll all have to resort to counting everything by hand from now on (or using Colin's way). I have contacted the developers of the API, but since it's through Google, who knows if they'll ever even respond...especially before our semester is over.

Sorry for the false hope in this application, but I don't see any way around this 200 entry limitation that Blogger has on their API. The most annoying part of it all is that the limit is not stated in the documentation anywhere! I spent countless hours trying to debug my JavaScript, assuming I had made a programmatical error along the way while counting the comments, but after a while I realized it wasn't my code. I began searching the Web to see if there was any sort of limitation and sure enough, 200 is the maximum!

If anyone can think of any neat ways to hack the thing or pull the information back differently from the API, I'd be more than happy to experiment with it some more, but I just don't think there's much of a way around it. I'm going to look into the different querying options they offer to see if I can query to different time frames or something than do the math once the two different results come back. Even so, that would still be a limit of 400, meaning the comments still would be incorrect.

If something ends up changing I'll be sure to post back with the results, but in the meantime I'm afraid we've reached the end....I guess it's like they say....All good things must come to end. LOL

Here's the link again for those who still want to use it to count the posts, but remember that once we surpass 200 posts as a class, that count will be off as well.

http://people.emich.edu/mmager/449


UPDATE:

I fixed it everybody!! The code to make this work is now a complete mess, but I basically had to make 8 different AJAX calls to the blogger API dividing it up in the query on a two week basis rather than getting it all at once. This allowed me to count the comments for each two weeks then add them all together in the end to get the total. You guys will notice your numbers are much higher and actually accurate now!

Nov 11, 2009

A Lazy Post Count Method

While I really like Matt's blog counting site, I decided it was too tedious to have to jump to an additional page and do all that searching and stuff. I appreciate his hard work and he most certainly displayed his skills learned in the class, but I figured there was an easier way to count your blogs.

All you need to do is put a unique keyword on each of your posts. My unique word is 'Colin'. Now that the keyword is added to the tag cloud, it will automatically count my posts for me.
As you can see in the image, I have posted 10 blogs prior to this post. How simple! Sadly this method will not work for comments, and for that case I will have to resort to Matt's blog and comment counting site.

Note: PLEASE don't add my name to your keywords on your posts. You will ruin my plan and it would be very rude!

Counting blog posts AND COMMENTS!!

Upon further investigation and testing on my original project counting blog posts and due to the suggestion from Terry, I realized that I should implement something to count our comments as well as our posts. Taking my code a step further to count the blog comments as well wasn't too much more work since I had already done the preliminary stuff. The changes came after my 'readBlogFeed' function. Once the posts have been counted and returned to the div on my HTML page, a new function I created called 'comments' is then called. This function is what I used to count the comments. It goes through the process of contacting the blogger API again and then I take the results and parse through them again using another function I created called 'readCommentsBlogFeed'. The 'readCommentsBlogFeed' function is similar to the 'readBlogFeed' function I created before, but instead of counting the authors of posts it counts the authors of comments.

Now the main difference between counting the posts and counting the comments is actually done in the PHP file on my server. The blogger API uses a different link for the comments, which is http://www.blogger.com/feeds/OUR_BLOG_ID/comments/default instead of the one just for posts which is http://www.blogger.com/feeds/OUR_BLOG_ID/posts/default.



As you can see, I also took the JavaScript coding a lot further to create a dynamic select box that automatically finds all the names from our class blog and sorts them and places them in a list for you. This was a little tricky to code, but it will prevent any typos or other errors that were occurring before. Basically, I made an initial call to the blogger API on the page load which got the XML and parsed through it for all the names of authors that have posted on our blog. Once it got the names I needed to create a function that removed any duplicate names. Upon sorting it alphabetically using JavaScript's sort() function on the array I created, I then passed the list into the function to remove the duplicates and only leave a list of our names. I also took Terry and Jassin's names and wrote them out in the JavaScript since they were in lower case and didn't follow the structure of everyone else's...(I'm kind of a neat freak) Here's a little bit of the code I used to make all this work:

Here's how I went about changing the names and using the sort() method to sort my array of names:


Removing duplicate names:


Creating the select box dynamically:


Feel free to use this neat little application to make sure you're staying up on the class requirements! It's on my people account Website at http://people.emich.edu/mmager/449/.

Let me know if any issues arise too and I'll fix them!