1

ここに画像の説明を入力

以下のコードを使用して、Facebook アプリがユーザー ストリームを投稿できるようにしようとしています。下部のコードは、コードを取得したサイトから動作しますが、私のものではありません。機能する場所: http://www.fbrell.com/fb.api/graph-me

2 番目のボールドの後の一番下のコードを参照してください。

以下のコードで何が欠けていますか?

    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"].",";

以下は動作しないコードです

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

2 に答える 2

1

これを試して、このコードを doPost 関数に入れます。そのためには、publish_stream 権限が必要です。「<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);
}
于 2013-04-11T06:24:55.500 に答える