简体   繁体   中英

Return after posting to before page (graph api facebook php sdk)

CLOSED

Just remove

echo("<script> top.location.href='" . $auth_url . "'</script>");

and

 change define('REDIRECT_URI

Hello this is my first question and i have some problem with facebook graph api.
I make application for update status from my site in canvas page.
this is the code

define('APP_ID', 'numbernumbernumber');
define('APP_SECRET', 'codecodecode');
define('REDIRECT_URI', 'canvaspagecanvanvaspage');
define('SCOPE','publish_actions,publish_stream');

require 'includes/php-sdk/facebook.php';

$facebook = new Facebook(array(
        'appId' => APP_ID,
        'secret' => APP_SECRET,
        'cookie' => true,
        'display' => 'touch'
    ));

$facebook->setAccessToken($access_token);
$user_id = $facebook->getUser();

$user = $facebook->getUser();
$access_token = $facebook->getAccessToken();

if ($user) {
try {
    $user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
}
}

$auth_url = "https://www.facebook.com/dialog/oauth?client_id=". APP_ID . "&redirect_uri=" . urlencode(REDIRECT_URI)."&scope=".SCOPE;

$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = @explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
    echo("<script> top.location.href='" . $auth_url . "'</script>");
}
$access_token=$data["oauth_token"];

and in html doc :

    <div id="fb-root"></div>
    <script>(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/id_ID/all.js#xfbml=1&appId=numbernumbernumber";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
    <div class="fb-login-button" autologoutlink="true"  onlogin="require('./log').info('onlogin callback')" data-show-faces="false" data-width="200" data-max-rows="1"></div><br >

<form enctype="multipart/form-data" action="https://graph.facebook.com/me/feed?message&access_token=<? echo $access_token ?>" method="post">

<br/>Write your status : 
<input name="message" type="text" value="">
<input type="submit" value="Kirim" /><br/></form>
  1. After posting status success, canvas (or iframe in canvas not return again)
    http://i.stack.imgur.com/4AZ7N.jpg ->posting success
    http://i.stack.imgur.com/OZbPX.jpg -> but canvas page ?
    please help me....

  2. If i open canvas page, it open canvas page....If i open link to my site, its always redirect to canvas page. please help me for not redirect to canvas page. thanks

May you give me the link to see how it works now?

And if your working on a canvas page, you can not leave the canvas page, if you want to send them to your site, you need to do it opening a new window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM