se' wait yo..
Cara Kerja BETMEN :P
Getting UserID and Name:
Pas User ngunjungin Blog dan Connected sama Account Facebook mereka (see: Add Facebook Connect to Your Blog in 8 Minutes :P ...), Aplikasi yang terpasang diBlog bakalan otomatis nyatet
userID
sama name
mereka.
var idUserYgLoginNih; var namaUserYgLoginNih; FB.getLoginStatus(function(tahMere){ if(tahMere.authResponse && tahMere.authResponse.userID){ idUserYgLoginNih = tahMere.authResponse.userID; FB.api('/'+idUserYgLoginNih,'get',{fields:'name'},function(tahMereLagi){ if(tahMereLagi.name){ namaUserYgLoginNih = tahMereLagi.name; } }); } });
Lihat hasil tahMereLagi
di graph.facebook.com/13?fields=name
Posting/Save The Data:
Terus buat nyimpen data Pengunjung
, Aplikasi posting ke wall-nya sendiri dengan menggunakan AppaccessToken
aplikasi tersebut (see: developers.facebook.com/tools/access_token/)
function tanyaPesbukGraphApi(uri){ var e = document.createElement('script'); e.async = 'true'; e.src = uri; document.getElementsByTagName('head')[0].appendChild(e); } function hasilKolbekPosting(apaan){ if(apaan.id){alert(apaan.id)} else if(apaan.error){alert(apaan.error.message)} else{alert(apaan)} } var aksestokenAplikasiYgDiPake = '217310991646263|emd4sw5oNS3koh3QZ0wBUodOHLU'; var idAplikasiYgDiPake = aksestokenAplikasiYgDiPake.split('|')[0]; var alamatYgDiKunjungi = window.location.href; var judulArticleYgDiKunjungi = document.title; var uriBuatPosting = 'https://graph.facebook.com/'; uriBuatPosting += idAplikasiYgDiPake+'/feed?method=POST'; uriBuatPosting += '&message='+judulArticleYgDiKunjungi; uriBuatPosting += '&link='+alamatYgDiKunjungi; uriBuatPosting += '&name='+namaUserYgLoginNih; uriBuatPosting += '&caption='+idUserYgLoginNih; uriBuatPosting += '&access_token='+aksestokenAplikasiYgDiPake; uriBuatPosting += '&callback=hasilKolbekPosting'; tanyaPesbukGraphApi(uriBuatPosting);
Read and Print Result:
Buat nampilin data para pengunjung, sekarang kita tinggal baca aja wall feed dari aplikasinya ^_*
document.write('<div id="laporan-betmen"></div>'); function hasilKolbekBacaWallFeed(apaan){ var tulisnih=''; if(apaan.data){ if(apaan.data.length==0){ tulisnih+='Datanya Kosong Coy..'; }else{ for(x in apaan.data){ tulisnih+='<div>'; if(apaan.data[x].caption && apaan.data[x].name){ tulisnih+='<img src="http://graph.facebook.com/'+apaan.data[x].caption+'/picture" style="width:32px; vertical-align:middle"/> '; tulisnih+='<a href="http://www.facebook.com/'+apaan.data[x].caption+'">'+apaan.data[x].name+'</a> '; } if(apaan.data[x].link && apaan.data[x].message){ tulisnih+='viewed: <a href="'+apaan.data[x].link+'">'+apaan.data[x].message+'</a> '; tulisnih+='at <code>'+apaan.data[x].created_time+'</code>'; } tulisnih+='</div>'; } if(apaan.paging){ tulisnih+='<div>'; if(apaan.paging.previous){ tulisnih+='<a href="javascript:void(0)" onClick="tanyaPesbukGraphApi(\''+apaan.paging.previous+'\')">previous</a> '; } if(apaan.paging.next){ tulisnih+='<a href="javascript:void(0)" onClick="tanyaPesbukGraphApi(\''+apaan.paging.next+'\')">next</a> '; } tulisnih+='</div>'; } } }else if(apaan.error){ tulisnih+=apaan.error.message; }else{ tulisnih+=apaan; } document.getElementById('laporan-betmen').innerHTML=tulisnih; } var limitBacaWallFeed = 5; var uriBacaWallFeed = 'https://graph.facebook.com/'; uriBacaWallFeed += idAplikasiYgDiPake+'/feed?fields='; uriBacaWallFeed += 'application,name,caption,link,message'; uriBacaWallFeed += '&limit='+limitBacaWallFeed; uriBacaWallFeed += '&access_token='+aksestokenAplikasiYgDiPake; uriBacaWallFeed += '&callback=hasilKolbekBacaWallFeed'; tanyaPesbukGraphApi(uriBacaWallFeed);Contoh full script bisa dilihat di..