简体   繁体   English

应用程序重定向到Facebook主页

[英]App Redirect to Facebook Home Page

This is My Facebook Application Source 这是我的Facebook应用程序源

<?php

require 'facebook.php';
require 'config.php';

if (isset($_GET['code'])){
  header("Location: " . $canvasPage);
  exit;
}

$fb = new Facebook(array(
                'appId' => 'xxx',
                'secret' => 'xxxx',
                'cookie' => true,
                                'fileUpload' => true,


));

$me = null;

$user = $fb->getUser();

if($user) {
    try {

            $me = $fb->api('/me'); 
    } catch(FacebookApiException $e) {
            error_log($e);
    }
}
//edit the permissions needed
$permsneeded='publish_stream,user_photos';

if ($me){}
else {
    $loginUrl = $fb->getLoginUrl(array(
                'scope' => $permsneeded,
                ));

    echo "
        <script type='text/javascript'>
        window.top.location.href = '$loginUrl';
        </script>
    ";

    exit;
}

if(isset($_GET['signed_request'])) {
    $fb_args="signed_request=". $_REQUEST
    ['signed_request']; }

$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("");
} 
$access_token   = $data["oauth_token"]; 

try {
$my = $fb->api('/me');
}catch(FacebookApiException $e) {
            error_log($e);
    }

$nam = $my['name'];
    $images = array(
        0 => 'celeb/1.jpg',
        1 => 'celeb/1.jpg',
        3 => 'celeb/1.jpg',
        4 => 'celeb/1.jpg',
        5 => 'celeb/1.jpg',
        6 => 'celeb/1.jpg',

    );
$image = $images[ rand(0,(count($images)-1)) ];

Some other php code

?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" >


My Code . 


</html>

i got 2 Problems . 我有2个问题。

  1. It is redirect to Facebook Home Page . 它被重定向到Facebook主页。 See Demo : https://apps.facebook.com/246435698815637/ 参见演示: https : //apps.facebook.com/246435698815637/
  2. this is "$image = $images[ rand(0,(count($images)-1)) ];" 这是“ $ image = $ images [rand(0,(count($ images)-1))]”; is not working some time . 一段时间没有工作。 it is didn't get image for imagecreatefromjpeg 它没有获得imagecreatefromjpeg的图像

Try like this and please avoid the blank statements. 尝试这样,请避免使用空白语句。

if(!($me)) 
{
    echo '<script> top.location.href="'.$facebook->getLoginUrl(array(
                    'req_perms' => $permsneeded,
                    'next' =>'https://apps.facebook.com/246435698815637/',
                    )). '";
          </script>';
    exit();
}

and second one is correct,it should work,but i don't get your point about imagecreatefromjpeg as you don't give any information about it.Paste your code where you have use that function. 第二个是正确的,它应该可以工作,但是我不明白关于imagecreatefromjpeg的观点,因为您没有提供任何有关它的信息。将您的代码粘贴到使用该函数的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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