2013-04-11 70 views
1

enter image description hereFacebook的API绘制我 - 发布到流

我试图让我的Facebook应用程序发布的用户使用下面的码流。 在底部的代码是从我得到的代码,但不是我的网站的作品。 如果它的工作原理:http://www.fbrell.com/fb.api/graph-me

看到代码在最底层之后的第二BOLD:

什么我在下面的代码失踪?

visible  //facebook application id, secret key here 
    $fbconfig['appid' ] = "MY###"; 

    $fbconfig['secret'] = "MY###"; 

    //set application urls here 
    $fbconfig['baseUrl'] = "MY###"; 
    if($id){ 
    $fbconfig['appBaseUrl'] = "http://apps.facebook.com/MY###/index.php?id=".$id; 
    } 
    else 
    { 
     $fbconfig['appBaseUrl'] = "http://apps.facebook.com/MY###/"; 
    } 


    $uid   = null; //facebook user id 

    try{ 
     include_once "facebook.php"; 
    } 
    catch(Exception $o){ 
     echo '<pre>'; 
     print_r($o); 
     echo '</pre>'; 
    } 
    // Create our Application instance. 
    $facebook = new Facebook(array(
     'appId' => $fbconfig['appid'], 
     'secret' => $fbconfig['secret'], 
     'cookie' => true, 
    )); 

    //Facebook Authentication part 
    $user= $facebook->getUser(); 
    $loginUrl = $facebook->getLoginUrl(
      array(
      'scope' => 'email,publish_actions,publish_stream,status_update,user_work_history,user_location,user_birthday,user_religion_politics', 
      'redirect_uri' => $fbconfig['appBaseUrl'],   ) 
    ); 


    $fbme = null; 

    if (!$user) { 
     echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>"; 
     exit; 
    } 
    else { 
     try { 
      $uid  = $facebook->getUser(); 
      $fbme  = $facebook->api('/'.$uid); 
      $friends = $facebook->api('/' . $facebook->getUser() . '/friends'); 
      //$gender = $facebook->api('/' . $facebook->getUser() . '/gender'); 
      $location = $fbme[location][name]; 
      $gender = $fbme[gender]; 




      /////foreach ($friends["data"] as $value) 
       ////{ 
       //echo '<li>'; 
       // echo '<div class="pic">'; 
       // echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture"/>'; 
       //echo '</div>'; 
       // echo '<div class="picName">'.$value["name"].'</div>'; 
       // echo '</li>'; 

       $NameID .= $value["name"]."|".$value["id"].","; 

这里是代码不低于WORK

<fb:login-button scope="read_stream,publish_stream"> 
    Grant Permissions to make more examples work 
</fb:login-button> 

<button onclick="doPost()">Post to Stream</button> 

<script> 
function userData() { 
    FB.api('/me', Log.info.bind('/me callback')); 
    FB.api('/me/friends', Log.info.bind('/me/friends callback')); 
    FB.api('/me/feed', Log.info.bind('/me/feed callback')); 
    FB.api(
    '/platform/feed', 
    { limit: 3 }, 
    Log.info.bind('/platform/feed limit: 3 callback') 
); 
} 
function publicData() { 
    FB.api('/platform', Log.info.bind('/platform callback')); 
    FB.api('/britneyspears', Log.info.bind('/britneyspears callback')); 
    FB.api('/this-will-error', Log.info.bind('/this-will-error callback')); 
} 
window.doPost = function() { 
    FB.api(
    '/me/feed', 
    'post', 
    { message: 'Trying the Graph' }, 
    Log.info.bind('/me/feed POST callback') 
); 
}; 

FB.getLoginStatus(function(response) { 
    if (response.status === 'connected') { 
    userData(); 
    } 
    publicData(); 
}); 
</script> 

//////////////////////// //////////// ///////////////////////// 更新..完整代码:

<? 






///////////////////////////////////////////// 
///////////////////////////////////////////// 

    //facebook application id, secret key here 
    $fbconfig['appid' ] = "NADA"; 

    $fbconfig['secret'] = "NADA"; 

    //set application urls here 
    $fbconfig['baseUrl'] = "NADA"; 
    if($id){ 
    $fbconfig['appBaseUrl'] = "NADA/index.php?id=".$id; 
    } 
    else 
    { 
     $fbconfig['appBaseUrl'] = "http://apps.facebook.com/NADA/"; 
    } 


    $uid   = null; //facebook user id 

    try{ 
     include_once "facebook.php"; 
    } 
    catch(Exception $o){ 
     echo '<pre>'; 
     print_r($o); 
     echo '</pre>'; 
    } 
    // Create our Application instance. 
    $facebook = new Facebook(array(
     'appId' => $fbconfig['appid'], 
     'secret' => $fbconfig['secret'], 
     'cookie' => true, 
    )); 

    //Facebook Authentication part 
    $user= $facebook->getUser(); 
    $loginUrl = $facebook->getLoginUrl(
      array(
      'canvas' => 1, 
      'scope' => 'publish_stream,email,user_about_me,user_birthday,user_website', 
      'scope' => 'read_stream,publish_stream,status_update,user_work_history,user_location,user_birthday,user_religion_politics,email', 
      'fbconnect' => 1, 
      'redirect_uri' => 'https://apps.facebook.com/vizzytesting',  ) 
    ); 


    $fbme = null; 

    if (!$user) { 
     echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>"; 
     exit; 
    } 
    else { 
     try { 
      $uid  = $facebook->getUser(); 
      $fbme  = $facebook->api('/'.$uid); 
      $friends = $facebook->api('/' . $facebook->getUser() . '/friends'); 
      //$gender = $facebook->api('/' . $facebook->getUser() . '/gender'); 
      $location = $fbme[location][name]; 
      $gender = $fbme[gender]; 




      /////foreach ($friends["data"] as $value) 
       ////{ 
       //echo '<li>'; 
       // echo '<div class="pic">'; 
       // echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture"/>'; 
       //echo '</div>'; 
       // echo '<div class="picName">'.$value["name"].'</div>'; 
       // echo '</li>'; 

       $NameID .= $value["name"]."|".$value["id"].","; 

       /// }   



       {?> 

<style type="text/css"> 
body { 
    margin-left: 0px; 
    margin-top: 0px; 
    margin-right: 0px; 
    margin-bottom: 0px; 
    background-image: url(../RosaryPromotion/images/Top.jpg); 
} 
.Top { 
    background-image: url(../RosaryPromotion/images/Top.jpg); 
    display: block; 
    height: 333px; 
} 
#Top { 
    background-image: url(../RosaryPromotion/images/White.png); 
    height: 370px; 
    width: 885px; 
} 
#Pic { 
    width: 90%; 
    border-top-style: none; 
    border-right-style: none; 
    border-bottom-style: none; 
    border-left-style: none; 
    position: relative; 
} 
.ProfilePic { 
    background-image: url(http://graph.facebook.com/<?=$facebook->getUser();?>/picture?type=large); 
    background-repeat: no-repeat; 
    background-position: center center; 
    position: absolute; 
    top: -6px; 
    left: -21px; 
    display: block; 
} 



#NameTag { 
    background-image: url(../RosaryPromotion/images/BlueButton.png); 
    background-repeat: no-repeat; 
    display: block; 
    height: 53px; 
    width: 257px; 
    position: absolute; 
    top: 121px; 
    line-height: 45px; 
    font-family: "Arial Black", Gadget, sans-serif; 
    color: #FFF; 
    padding-left: 20px; 
    font-size: 18px; 
    left: -32px; 
} 

#RegisteredTimes { 
    background-image: url(../RosaryPromotion/images/BlueButton.png); 
    background-repeat: no-repeat; 
    display: block; 
    height: 53px; 
    width: 257px; 
    position: absolute; 
    top: 215px; 
    line-height: 45px; 
    font-family: "Arial Black", Gadget, sans-serif; 
    color: #FFF; 
    padding-left: 20px; 
    font-size: 18px; 
    left: -31px; 
} 
</style> 

       <table width="878" border="0" align="center" cellpadding="0" cellspacing="0" id="Top"> 
       <tr> 
        <th width="878" align="center" valign="top" scope="col"> 

<div align="left" id="Pic"> 



     <div class="ProfilePic" id="ProfilePic"><img src="../RosaryPromotion/images/Photo.png" width="228" height="224" alt="PhotoFrame" /></div> 

    <div class="NameTag" id="NameTag"><?="$fbme[email]";?></div> 
    <div class="RegisteredTimes" id="RegisteredTimes"><?="$fbme[gender]";?></div> 



        </div> 
        <? echo count(explode(",",$NameID)); echo "<br>"; echo $fbme[location][name]; 
       echo "<br>"; 
       echo $fbme[birthday]; 
       echo "<br>"; 
       echo $fbme[gender]; 
       echo "<br>"; 
       echo $fbme[religion];?> 

<fb:login-button scope="read_stream,publish_stream"> 
    Grant Permissions to make more examples work 
</fb:login-button> 

<button onclick="doPost()">Post to Stream</button> 

<script> 
FB.init({ 
appId : '144220342416564', 
frictionlessRequests: true, 
status: true, 
xfbml: true, 
oauth: true 
}); 


function fbLoginStatus() 
{ 
FB.getLoginStatus(function(response) { 
    console.log(response); 
    if (response.status === 'connected') { 
     access_token = FB.getAuthResponse()['accessToken']; 
     doPost(); 
    } else { 
     fblogin(); 
    } 
}); 
} 


function fblogin() 
{ 
FB.login(function(response) { 
    if (response.authResponse) { 
     console.log(response); 
     access_token = FB.getAuthResponse()['accessToken']; 
     doPost(); 
    } else { 
     console.log('User cancelled login or did not fully authorize.'); 
    } 
}, {scope: 'publish_stream'}); 
} 

function doPost(){ 

var obj = { 
      method: 'feed', 
      link: 'http://example.com', 
      picture:'http://suvudu.com/files/mt-files/Edward%20Cullen.jpg', 
      name:'title', 
      caption: 'Caption', 
      description:'Description' 
      }; 
console.log(obj); 
function callback(response) { 
     document.getElementById('msg').innerHTML = "Post ID: " + response['post_id']; 
    } 

FB.ui(obj, callback); 
} 
</script> 

        </th> 
       </tr> 
       </table> 
       <p> 
       <? } 

     } catch (FacebookApiException $e) { 
      echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>"; 
      exit; 
     } 
    } 
    /*$uid=$user; 
    function d($d){ 
     echo '<pre>'; 
     print_r($d); 
     echo '</pre>'; 

    } 

    //FQL function 
    function fqlQuery($q){ 
    global $facebook; 
    $param = array(
     'method' => 'fql.query', 
     'query'  => $q, 
     'callback' => '' 
    ); 
    //return $fqlResult = $facebook->api($param); 
}*/ 
include("rosaryDatabase.php"); 
?> 
</p> 

回答

1

试试这个,把这段代码放到你的doPost函数中,你必须有publish_strea对此的许可。 “把<div id="fb-root"></div>在HTML的身体和所有下面的代码在脚本标签页的”

// Load the SDK asynchronously 
(function(d, s, id){ 
var js, fjs = d.getElementsByTagName(s)[0]; 
if (d.getElementById(id)) {return;} 
js = d.createElement(s); js.id = id; 
js.src = "//connect.facebook.net/en_US/all.js"; 
fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'fb-root')); 

FB.init({ 
appId : 'xxxxxxxxxxxxxxxx', 
frictionlessRequests: true, 
status: true, 
xfbml: true, 
oauth: true 
}); 


function fbLoginStatus() 
{ 
FB.getLoginStatus(function(response) { 
    console.log(response); 
    if (response.status === 'connected') { 
     access_token = FB.getAuthResponse()['accessToken']; 
     doPost(); 
    } else { 
     fblogin(); 
    } 
}); 
} 


function fblogin() 
{ 
FB.login(function(response) { 
    if (response.authResponse) { 
     console.log(response); 
     access_token = FB.getAuthResponse()['accessToken']; 
     doPost(); 
    } else { 
     console.log('User cancelled login or did not fully authorize.'); 
    } 
}, {scope: 'publish_stream'}); 
} 

function doPost(){ 

var obj = { 
      method: 'feed', 
      link: 'http://abc.com', 
      picture:'http://suvudu.com/files/mt-files/Edward%20Cullen.jpg', 
      name:'title', 
      caption: 'Caption', 
      description:'Description' 
      }; 
console.log(obj); 
function callback(response) { 
     document.getElementById('msg').innerHTML = "Post ID: " + response['post_id']; 
    } 

FB.ui(obj, callback); 
} 
+0

我试过这个,它没有工作。我把发布流放到了我的应用中,但没有显示出来。我会发一张照片。 – 2013-04-11 06:35:44

+0

我在这篇文章的顶部添加了一张图片。 – 2013-04-11 06:39:26

+0

它没有发布流的权限,它是扩展权限 – 2013-04-11 06:41:07

0

事实上,你必须创建在developer.facebook.com应用程序设置,如果你没有创建的应用程序,如果你已经创建的应用程序检查应用程序设置中的网址

+0

不错,哪一部分? – 2013-04-11 07:43:26

+0

https://developers.facebook.com/apps去那里,为你的网站创建应用程序,你将有你的网站的appkey和密钥,并在你的代码中使用它 – 2013-04-11 08:36:58

+0

@PapaDeBeau你有没有检查 – 2013-04-12 09:09:55