trollolodn

#javascript: graph facebook example

Sep 11th, 2013
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.89 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5.         <title>New Graph api & Javascript Base FBConnect Tutorial | Thinkdiff.net</title>
  6.    </head>
  7.    <body>
  8.        <div id="fb-root"></div>
  9.        <script type="text/javascript">
  10.            window.fbAsyncInit = function() {
  11.                FB.init({appId: '1377993789087927', status: true, cookie: true, xfbml: true});
  12.  
  13.                 /* All the events registered */
  14.                 FB.Event.subscribe('auth.login', function(response) {
  15.                     // do something with response
  16.                     login();
  17.                 });
  18.                 FB.Event.subscribe('auth.logout', function(response) {
  19.                     // do something with response
  20.                     logout();
  21.                 });
  22.  
  23.                 FB.getLoginStatus(function(response) {
  24.                     if (response.session) {
  25.                         // logged in and connected user, someone you know
  26.                         login();
  27.                     }
  28.                 });
  29.             };
  30.             (function() {
  31.                 var e = document.createElement('script');
  32.                 e.type = 'text/javascript';
  33.                 e.src = 'https://connect.facebook.net/en_US/all.js';
  34.                 e.async = true;
  35.                 document.getElementById('fb-root').appendChild(e);
  36.             }());
  37.  
  38.             function login(){
  39.                 FB.api('/me', function(response) {
  40.                     document.getElementById('login').style.display = "block";
  41.                     document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";
  42.                 });
  43.             }
  44.             function logout(){
  45.                 document.getElementById('login').style.display = "none";
  46.             }
  47.  
  48.             //stream publish method
  49.             function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
  50.                 FB.ui(
  51.                 {
  52.                     method: 'stream.publish',
  53.                     message: '',
  54.                     attachment: {
  55.                         name: name,
  56.                         caption: '',
  57.                         description: (description),
  58.                         href: hrefLink
  59.                     },
  60.                     action_links: [
  61.                         { text: hrefTitle, href: hrefLink }
  62.                     ],
  63.                     user_prompt_message: userPrompt
  64.                 },
  65.                 function(response) {
  66.  
  67.                 });
  68.  
  69.             }
  70.             function showStream(){
  71.                 FB.api('/me', function(response) {
  72.                     //console.log(response.id);
  73.                     streamPublish(response.name, 'Thinkdiff.net contains geeky stuff', 'hrefTitle', 'http://thinkdiff.net', "Share thinkdiff.net");
  74.                 });
  75.             }
  76.  
  77.             function share(){
  78.                 var share = {
  79.                     method: 'stream.share',
  80.                     u: 'http://thinkdiff.net/'
  81.                 };
  82.  
  83.                 FB.ui(share, function(response) { console.log(response); });
  84.             }
  85.  
  86.             function graphStreamPublish(){
  87.                 var body = 'Reading New Graph api & Javascript Base FBConnect Tutorial from Thinkdiff.net';
  88.                 FB.api('/me/feed', 'post', { message: body }, function(response) {
  89.                     if (!response || response.error) {
  90.                         alert('Error occured');
  91.                     } else {
  92.                         alert('Post ID: ' + response.id);
  93.                     }
  94.                 });
  95.             }
  96.  
  97.             function fqlQuery(){
  98.                 FB.api('/me', function(response) {
  99.                      var query = FB.Data.query('select name, hometown_location, sex, pic_square from user where uid={0}', response.id);
  100.                      query.wait(function(rows) {
  101.                        
  102.                        document.getElementById('name').innerHTML =
  103.                          'Your name: ' + rows[0].name + "<br />" +
  104.                          '<img src="' + rows[0].pic_square + '" alt="" />' + "<br />";
  105.                      });
  106.                 });
  107.             }
  108.  
  109.             function setStatus(){
  110.                 status1 = document.getElementById('status').value;
  111.                 FB.api(
  112.                   {
  113.                     method: 'status.set',
  114.                     status: status1
  115.                   },
  116.                   function(response) {
  117.                     if (response == 0){
  118.                         alert('Your facebook status not updated. Give Status Update Permission.');
  119.                     }
  120.                     else{
  121.                         alert('Your facebook status updated');
  122.                     }
  123.                   }
  124.                 );
  125.             }
  126.         </script>
  127.  
  128.         <h3>New Graph api & Javascript Base FBConnect Tutorial | Thinkdiff.net</h3>
  129.        <p><fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream,user_about_me"></fb:login-button></p>
  130.  
  131.        <p>
  132.            <a href="#" onclick="showStream(); return false;">Publish Wall Post</a> |
  133.             <a href="#" onclick="share(); return false;">Share With Your Friends</a> |
  134.             <a href="#" onclick="graphStreamPublish(); return false;">Publish Stream Using Graph API</a> |
  135.             <a href="#" onclick="fqlQuery(); return false;">FQL Query Example</a>
  136.         </p>
  137.  
  138.         <textarea id="status" cols="50" rows="5">Write your status here and click 'Status Set Using Legacy Api Call'</textarea>
  139.         <br />
  140.         <a href="#" onclick="setStatus(); return false;">Status Set Using Legacy Api Call</a>
  141.  
  142.         <br /><br /><br />
  143.         <div id="login" style ="display:none"></div>
  144.         <div id="name"></div>
  145.  
  146.     </body>
  147. </html>
Advertisement
Add Comment
Please, Sign In to add comment