dongqie5529 2015-03-24 16:24
浏览 44

facebook连接访问令牌保存为php会话中断代码

I am trying to pass access token as a php session

Something weird is happening and I can't understand why.

fbconfig.fb

<?php
session_start();
// added in v4.0.0
require_once 'autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// init app with app id and secret
 FacebookSession::setDefaultApplication( 'xxxxxxxx','xxxxxxxxx' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://www.something.net/triviapp/1353/fbconfig.php' );
try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}
// see if we have a session
if ( isset( $session ) ) {
  // graph api request for user data
  $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();
    $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
    $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
    $firstname = $graphObject->getProperty('first_name');
    $lastname = $graphObject->getProperty('last_name');
    $femail = $graphObject->getProperty('email');    // To Get Facebook email ID
/* ---- Session Variables -----*/
    $_SESSION['FBID'] = $fbid;           
    $_SESSION['FULLNAME'] = $fbfullname;
    $_SESSION['EMAIL'] =  $femail;  
    $_SESSION['firstname'] =  $firstname;
    $_SESSION['lastname'] =  $lastname;

    $accessToken = $session->getAccessToken();
    $_SESSION['accesstoken'] =  $accessToken;


    //echo $_SESSION['accesstoken'];
   /* ---- header location after session ----*/
header("Location: index.php");
} else {
  $loginUrl = $helper->getLoginUrl();
 header("Location: ".$loginUrl);
}
?>

so far so good. I get connected and I get the access token and send user to index.php

index.php is where facebook connects starts and I check to see if I have a facebook session. if I don't I send user to above file fbconfig.php, eitherwise I send user to the html5 app (a file named mobile.php)

anyway when I try to access $_SESSION['accesstoken'] in mobile.php the code breaks. The code just end itself where I try to output that session and I can't understand why.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据