应用程序重定向到Facebook主页

时间:2012-11-05 05:52:47

标签: php facebook facebook-graph-api

这是我的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>

我遇到了2个问题。

  1. 重定向到Facebook主页。请参阅演示:https://apps.facebook.com/246435698815637/
  2. 这是“$ image = $ images [rand(0,(count($ images)-1))];”一段时间没有工作。它没有得到imagecreatefromjpeg的图像

1 个答案:

答案 0 :(得分:0)

请尝试这样做,请避免使用空白的陈述。

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

第二个是正确的,它应该可以工作,但我不明白你对imagecreatefromjpeg的看法,因为你没有提供任何关于它的信息。在你使用该功能的地方使用代码。