2012-07-22 41 views
0

我的index.php爲什麼閱讀開放圖形動作不正確的URL

在標籤頭

我輸入代碼

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" 
     xmlns:fb="https://www.facebook.com/2008/fbml"> 

<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# website: http://ogp.me/ns/website#"> <meta property="fb:app_id" content="418895381495750" /> 
    <meta property="og:site_name" content="Social News" /> <meta property="og:title" content="Sample Title" /> 
    <meta property="og:description" content="Sample Artice" /> 
    <meta property="og:type" content="website" /> 
    <meta property="og:image" content="http:www.myurl.com/wallpaper.png" /> <meta property="og:url" content="<?php echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; ?>"/> </head> 

和標籤體輸入

<div id="wrapper" 
    <div id="bottom"> 
     <?php 
      $p=$_GET["p"]; 
      switch($p) 
      { 
       case "news": require "blocks/news.php"; break; 
       case "title": require "blocks/tile.php"; break; 
       default: require "blocks/home.php"; 
      } 
     ?> 
    </div> 
</div> 

在我news.php輸入代碼

<div id="fb-root"></div> 
      <script> 
      window.fbAsyncInit = function() { 
       FB.init({ 
        appId  : '41834663463370', // App ID 
        oauth  : true, 
        status  : true, // check login status 
        cookie  : true, // enable cookies to allow the server to access the session 
        xfbml  : true // parse XFBML 
       }); 

      FB.login(function(response) { 
     if (response.authResponse) { 
      console.log('Access Token: ' + response.authResponse.accessToken); 
     } else { 
      console.log('User cancelled login or did not fully authorize.'); 
     } 
    },{scope:'publish_stream'}); 


      }; 

      (function(d){ 
       var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
       js = d.createElement('script'); js.id = id; js.async = true; 
       js.src = "//connect.facebook.net/en_US/all.js"; 
       d.getElementsByTagName('head')[0].appendChild(js); 
      }(document)); 
     </script> 


<script type="text/javascript"> 
    function readnews() 
    { 
    FB.api(  '/me/news.reads?article=<?php echo 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>','post', 
      function(response) { 
       var msg = 'Error occured'; 
       if (!response || response.error) { 
        if (response.error) { 
         msg += "\n\nType: "+response.error.type+"\n\nMessage: "+response.error.message; 
        } 
        alert(msg); 
       } else { 
        alert("Post timeline"); 
       } 
      }); 
    } 
    </script> 

但我沒有你瞭解爲什麼在時間軸上顯示url文件index.php
例如:Adam閱讀Sample Tile。 - >http://myurl.com/index.php
不顯示的URL我的帖子http://myurl.com/index.php?p=news&id= {$ _getid}

回答

0

你顯然缺少查詢字符串,試試這個:

<?php $currentUrl = sprintf('http%s://%s%s%s', 
    $_SERVER['HTTPS'] ? 's' : '', 
    $_SERVER['SERVER_NAME'], 
    $_SERVER['REQUEST_URI'], 
    $_SERVER['QUERY_STRING'] 
); ?> 

FB.api('/me/news.reads?article=<?php echo $currentUrl; ?>', 'post', ... 
+0

感謝,但它仍然顯示URL的index.php – 2012-07-23 02:34:14