Php 为什么打开图形中的读取操作url不正确

Php 为什么打开图形中的读取操作url不正确,php,javascript,facebook,facebook-opengraph,Php,Javascript,Facebook,Facebook Opengraph,my 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#"&

my 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="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>


您显然缺少查询字符串,请尝试以下操作:

<?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', ...

api('/me/news.reads?article=',post'。。。
<?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', ...