0

我的 index.php

在标签头中我输入代码

<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}

4

1 回答 1

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', ...
于 2012-07-22T13:45:02.633 回答