Kalo ini sih udah pasti wajib ada.. (asal jangan dobel-dobel aja)
<div id="fb-root"></div> <script type="text/javascript"> var idAplikasiGue = '333487403180'; window.fbAsyncInit = function(){ FB.init({ appId: idAplikasiGue, status: true, cookie: true, xfbml: true }); }; (function() { var e = document.createElement('script'); e.async = 'true'; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); </script>
Deteksi User & Permissions.. (Secara manual pake onClick event)
CSS..
<style type="text/css">
#tempat-kontent img#gambar-user{
float:left;
padding:0px 7px 0px 0px;
border:0px;
max-width:100px; _width:100px;
}
#tempat-kontent h3#nama-user{
margin-left:110px;
}
#klik-login input.button{
font-family: 'lucida grande',tahoma,verdana,arial,sans-serif;
background:#617AAC url(http://2.bp.blogspot.com/_bBL9ze_JZsw/TTkfFTP1LiI/AAAAAAAAALM/88pCEE5Ck0M/s1600/rock.gif) no-repeat scroll 4px 2px;
color: #FFFFFF;
font-weight: bold;
border: 1px outset #29447E;
-moz-border-radius: 5px; border-radius: 5px;
padding:2px 7px 2px 20px;
cursor: pointer;
margin-top:5px;
}
#klik-login input.button:hover{
background-color: #011A4C;
color: yellow;
}
</style>
HTML..
<div id="tempat-kontent" style="display:none;">
<img id="gambar-user" src="http://static.ak.fbcdn.net/rsrc.php/v1/yb/r/GsNJNwuI-UM.gif"/>
<h3 id="nama-user"><img src="http://static.ak.fbcdn.net/rsrc.php/v1/yb/r/GsNJNwuI-UM.gif"/></h3>
<hr style="clear:both;"/>
</div>
<center id="klik-login">
<input type="button" class="button" onClick="loginDong()" value="Click Here to Begin.."/>
</center>
JavaScript..
<script type="text/javascript"> function loginDong(){ FB.login(klikLogin,{perms:'read_stream,publish_stream'}); } function klikLogin(response){ if (response.session){ if(response.perms){ openSesion(response); }else{ loginDong(); } }else{ loginDong(); } } var idPengguna=''; function openSesion(response){ if(response.session.uid){ document.getElementById('klik-login').style.display='none'; document.getElementById('tempat-kontent').style.display='block'; idPengguna=response.session.uid; document.getElementById('gambar-user').src='http://graph.facebook.com/'+idPengguna+'/picture?type=normal'; FB.api('/'+idPengguna+'?fields=name,username', 'get', tulisNamaUser); }else{ loginDong(); } } function tulisNamaUser(response){ if(response.name && response.username){ document.getElementById('nama-user').innerHTML='<a href="http://www.facebook.com/'+response.username+'" target="_blank">'+response.name+'</a>'; }else if(response.name){ document.getElementById('nama-user').innerHTML='<a href="http://www.facebook.com/profile.php?id='+idPengguna+'" target="_blank">'+response.name+'</a>'; }else{ document.getElementById('nama-user').innerHTML='wkwkwkk.. doDOL nih Script-nya!! :P'; } } </script>
Buat nge-Like sebuah postingan.. (pake Facebook JavaScript SDK)
HTML..
<label for="masukan-id-post">Masukan Post_id:</label>
<input type="text" id="masukan-id-post" value="100000175501773_233130340036148" onClick="this.select()" style="width:225px;"/>
<br/>
<a onClick="likePostinganDong(document.getElementById('masukan-id-post').value)" style="cursor:pointer;">coba dong..</a>
<img id="gambar-loading-like" src="http://static.ak.fbcdn.net/rsrc.php/v1/yb/r/GsNJNwuI-UM.gif" style="display:none;"/>
JavaScript..
<script type="text/javascript"> function likePostinganDong(idPostingan){ document.getElementById('gambar-loading-like').style.display='inline-block'; FB.api('/'+idPostingan+'/likes', 'post', tulisResponNya); } function tulisResponNya(respon){ document.getElementById('gambar-loading-like').style.display='none'; if(respon.error){ alert(respon.error.message) }else{ alert(respon); } } </script>
Format post_id yang digunakan:
userIDPostID
100000175501773233130340036148
Sayangnya Facebook
gak nerimaformat userNamePostID
Dapetin Post_IDs.. (Facebook JavaScript SDK)
HTML..
<label for="id-input">ID or UserName <input id="id-input" type="text" value="" onClick="this.select()"/> </label> <br/> <label for="howmuch"> How much? <select id="howmuch"> <option value="5" selected="selected">5 Posts</option> <option value="10">10 Posts</option> </select> </label> <label for="where">Where? <select id="where"> <option value="home" selected="selected">My home feed</option> <option value="feed">wall feed</option> </select> </label> <div id="lapor-gan"></div> <div id="posts-list"></div> <input type="button" class="button" onClick="cariPostIds(document.getElementById('id-input').value, document.getElementById('howmuch').value, document.getElementById('where').value)" value="coba dong.."/>
JavaScript..
<script type="text/javascript"> function cariPostIds(userNya,howmuch,where){ var laporGan = document.getElementById('lapor-gan'); var postslist = document.getElementById('posts-list'); var daptarPostIds=[]; if(userNya==''){userNya='me'} if(userNya=='me'){ //mau diapain? }else{where='feed'} laporGan.innerHTML='<img src="http://static.ak.fbcdn.net/rsrc.php/v1/yb/r/GsNJNwuI-UM.gif"/> '; laporGan.innerHTML+='<small>detecting Posts please wait..</small>'; postslist.innerHTML=''; FB.api('/'+userNya+'/'+where, 'get', {limit:howmuch}, function(response){ if(response.data){ for(x in response.data){ if(response.data[x].id){ daptarPostIds[x]=response.data[x].id; postslist.innerHTML+=response.data[x].id+'<br/>'; } } laporGan.innerHTML='<h3><big>'+daptarPostIds.length+'</big> Posts detected..!</h3> '; }else if(response.error){ laporGan.innerHTML='<h3><big>Error</big> '+response.error.message+'</h3> '; }else{ laporGan.innerHTML='<h3><big>'+response+'</big></h3> '; } }); } </script>
Tar Lanjut..
13 comments:
kk gk ngrti maksunya ni..
100000175501773_233130340036148
tu ID ap kk
100000175501773_233130340036148
(itu post id kayanya)
wakwakkwa
Wkakak Ikut Coment AHkk
lanjutannya gmn gan???? :bingung
tlong kk masuk ke blog saya , bikin apss udh stengah jadi , mhon ptunjuk pa yg kurang ? http://yhonezzblog.blogspot.com/
susah kali
sudah gan tapi gagal ?
knpa itu bsa trjadi gan , nah pas detecting pos koq ga bsa gan malah jadinya setenga2 gtu kya punya saya gan . . .
berhasil
pas detecting pos script diatas gak ditambahin "else" jadi kalo "response" nya "error" bukan "data" tampilan gak ada yang berubah.. coba aja dirubah scriptnya tambahin "else"
G jadi-Jadi euy (mumet)
kak irland tolong dibantu ya, Kaka baek deh
gua gk ngerti ne soB.!!
jelasin doNk
a ari warna orange paranti naon
nu hejo paranti naon ?
nu biru oge ?
wajib di isi teu a ?
itu cuman warna buat ngebedain aja gan.. biar agak enak dibaca,,
kalo soal String Object variable javascript,, dikit-dikit bisa dibaca diwww.w3schools.com/js
Post a Comment