JavaScript


27
Jan 11

Faceook Connect: FB.UI error: Sorry, something went wrong.

Today i’m working on a facebook application which needs to post to wall of user’s friend!
Here is my application http://apps.facebook.com/axcotobuzz/, and it’s a IFRAME app! So i used FB.UI with method feed or stream.publish to post to wall!

I read document carefully, it seems everything is easy here:

http://developers.facebook.com/docs/reference/javascript/fb.ui/

http://fbdevwiki.com/wiki/FB.ui

http://developers.facebook.com/docs/reference/dialogs/feed

http://developers.facebook.com/docs/reference/dialogs/feed

After go thorought over them, i then wrote my code as below:

<script>
 challenge.setQuestion('<?php echo $friend->id ?>', '<?php echo $question['id'] ?>');
 FB.ui({
 method: 'stream.publish',
 display: 'popup',
 name: 'Axcoto',
 link: 'http://axcoto.com/',
 message: '90',
 to: 100001785219571,
 redirect_uri: '<?php echo $facebook->conf['canvas']['url'];?>quizz/publishPostBack/',
 }, function () {

 });

 </script>

Clear cache, refresh app…and what i got

Sorry, something went wrong.

We’re working on getting this fixed as soon as we can.

I re-read document carefully, nothing is wrong with my code! And someone is encountering it too

http://developers.facebook.com/docs/reference/dialogs/feed

After some effort, realize that its cause is extra parameter “next” in URL which FB.UI generate

Look at my URL:

http://www.facebook.com/dialog/feed?

app_id=188071914544841&
caption=AAA&description=89.&
link=http%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Freference%2Fdialogs%2F&locale=en_US&message=90!&name=Facebook%20Dialogs&next=http%3A%2F%2Fstatic.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%23cb%3Df35e4913995012%26relation%3Dopener%26frame%3Df65d68044d6ac%26result%3D%2522xxRESULTTOKENxx%2522&picture=http%3A%2F%2Ffbrell.com%2Ff8.jpg&redirect_uri=http://axcoto.homelinux.org/axcotobuzz/quizz&sdk=joey

I then tried to removed it, took it like this:

http://www.facebook.com/dialog/feed?

app_id=188071914544841&
caption=AAA&description=89.&
link=http%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Freference%2Fdialogs%2F&locale=en_US&message=90!&name=Facebook%20Dialogs&picture=http%3A%2F%2Ffbrell.com%2Ff8.jpg&redirect_uri=http://axcoto.homelinux.org/axcotobuzz/quizz&sdk=joey

Manually enter it on address bar, it works!!! Amazing, but it DOES work!

I dunno the reason, but after figuring out it, i set “next” to null like this:


<script>
 challenge.setQuestion('<?php echo $friend->id ?>', '<?php echo $question['id'] ?>');
 FB.ui({
 method: 'stream.publish',
 display: 'popup',
 name: 'Axcoto',
 link: 'http://axcoto.com/',
 message: '90',
 to: 100001785219571,
 redirect_uri: '<?php echo $facebook->conf['canvas']['url'];?>quizz/publishPostBack/',
 next: null
 }, function () {

 });

 </script>

Clear cache, F5! It works like a charm!

Hope this helps you!


28
May 09

Find the day in week which you are wasting lots of time to tweet

Yeah, you know! Social Network is killing us! We wasted lots of time in it! So, i want to find the day which i tweet too many! After reading document on twitter search API i started on this, a script that will draw a plot for your tweets in lastest seven days(1 week)! That way, you can know which day you tweet many and the progress of your tweeting!
Twitter Search API returns data in many format JSON, ATOM,..! Then we can manipulate with that data! For my simple script, i will use JSON!

Try demo first

The idea:

-Get all tweets in lastest 7 days(Because we want to stat in a week)! We will receive result in JSON object
-Loop thorough the result and sum all tweets in the same day!
-Then draw a plot based on that data!
-Use jQuery& Flot to parse JSON, send, receive request and draw plot

The first, you need to make familiar with Twitter Search API!

This API return all tweets which match with a specify query(you like this query on URL as GET parameter like ?q=from:kureikain&since=2009-05-23)! The important paramete is

-rpg

-since

-q:

Ok, enough for concept:))! Now, read code below!

var myDate=new Date();
myDate.setDate(myDate.getDate()-6);
var month = (myDate.getMonth() + 1) + '';
if (month.length==1) {
month = '0' + month;
}

Twitter use a “since” parameter to define when we are searching tweets since! It formats like 2009-05-09, 2009-12-22! Take a notice on zero leading in day or month! If you pass “since=2009-5-11″, the searching doesn’t function!

We are getting data for last 7 days!So, create a Date object for current date then substract by 6 to find “since” day!

After that, we send request to find tweet by out user and since that day! We will make request to this

$.getJSON(
‘http://search.twitter.com/search.json?callback=?&rpp=1500&since=’ + since + ‘&q=from:’ + username ,
function(data) {
//console.log(data);
$.each(data, function(i, tweets) {
if (tweets.length != undefined)
//console.log(tweets);

//Do we have any result? Every tweets has created_at
if (tweets[0].created_at != undefined) {
for (i = 0; i < tweets.length; i++) {
whichday = (new Date(tweets[i].created_at)).getDay();
//console.log(usageDay);
stats[whichday]++;
};
}

})

//console.log(stats);
var d1 = [];
var y, point;

for (var i = 0; i <= 6; i++) {
y = stats[i];
x = i;
d1.push([x, y] );
}
$.plot($(“#placeholder”), [
{
label : "Daily tweet of <b>" + username + "</b>",
data : d1,
lines: { show: true },
points: { show: true },
xaxis: { mode: 'time' },
yaxis: { min: 0 }
}
],
{
xaxis: {
min: 0,
ticks: [[0, "Sun"],
[1, "Mon"],
[2, "Tue"],
[3, "Wed"],
[4, "Thu"],
[5, "Fri"],
[6, "Sat"]],
max: 6
}
}
);

}
);


25
May 09

jQuery Flash Message Plugin

I’m sure that sometime you need to display messages which auto disappear after few seconds! Many people use fadeOut for this! Yes, in most of case, it works great and that’s all! But how if you want to control the display of messages! Such as you want it disappear after 100 seconds, or you want to change content of message easily…! I tried to find a jQuery plug-in for this but well, i didn’t find anything! And that’s the reason why i wrote the very simple(Yes, very very simple) Jquery plug-in for this!

HOW TO USE