I have been implementing Twitter Cards on our sites in last few days. I'm at the stage where everything is implemented however, I do need to get them validated and request for approval.
This you would think is the easiest part of entire development process - that's until you get "Server error, please try again." error and the only reply I have got from Twitter is "we know... keep trying".
So after retrying by hand few times I have decided that I have better things to do with my time; hence the script.
What it does?
- Every 10 seconds retry (push retry button).
- If you hit rate limiter wait for 10 turns (10 x 10 seconds)
- If you pick up that there is no error message then you are finished.
Warning: I have used this to validate some of my Twitter Cards, however I do not give any guarantee that this will work for you and not block your twitter account or cause any other damage.
var tries = 0;
var rateLimit = 10;
var int=self.setInterval(function(){
var button = $("div.icon-refresh");
if(button.length>0){
var error = $("span.error-label-text:contains('Server error'):visible");
var rateLimiter = $("span.error-label-text:contains('Rate')");
// Retry function
var retryNow = function(){
button.click();
tries++;
console.log("Attempt: "+tries);
}
if(error.length>0){
retryNow();
if(rateLimit <= 0){
rateLimit = 10;
console.log("Rate limiter reset to 10 seconds");
}
}else if(rateLimiter.length>0){
console.log("Rate limiter - wait for " + rateLimit + " seconds");
rateLimit--;
}else{
// Final check for any errors
if($("span.error-label-text:visible").length==0){
console.log("Success!");
}else{
console.log("Another error detected re-trying anyway!");
retryNow();
}
}
}
},10000);
Requirements
- Twitter Account
- Chrome / Firefox with Firebug
|
Figure 3.1 |
Steps
- Open your browser (Chrome is my browser of choice)
- Go to URL https://dev.twitter.com/docs/cards/validation/validator
|
Figure 6.1 |
|
Figure 7.3 |
- It might require you to log in, so use your twitter account and login then use the URL to login again.
- Pick a card from "Card Catalog" once the page loads. (See Figure 3.1)
- Select "Validate & Apply" tab
- Enter your site's URL
- Wait for "Error to show up" (See Figure 6.1)
- Now we are set for running the script
|
Figure 7.6 |
- Right click the page and select "Inspect Element"
- Development tools will appear at the bottom of the page.
- Go to the Console tab
- Copy / Paste script from above to the console.
- Press Enter to start retry.
- See figure 7.6 for example output.
|
Figure 7.7 |
- Once its validated you will get success message. (See figure 7.7)
No comments :
Post a Comment