0

这是我的 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 获取图像
4

1 回答 1

0

尝试这样,请避免使用空白语句。

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

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

于 2012-11-05T06:47:54.180 回答