2

DB を facebook API と統合しようとしていますが、これは本当に新しいので、助けていただければ幸いです。

私はいつも0を取得しています

使用する

$uid = $facebook->getUser()

同様の問題を調べましたが、関連する解決策が見つかりませんでした。

PHP

if($_REQUEST['action']=="signup" && $_REQUEST['auth']=="facebook" && !empty ($_REQUEST['auth'])  && !empty ($_REQUEST['action']) )
{

require_once('libs/facebook/src/facebook.php');

$config = array();
$config['appId'] = 'xxxx';
$config['secret'] = 'xxxxxx';

$facebook = new Facebook($config);
$uid = $facebook->getUser();
echo $uid;
}

//else {} normal sign up here with all the error checking

HTML

<div class="fb-login-class">
      <div class="fb-login-button" autologoutlink="true" scope="publish_stream" perms="email,user_birthday" data-show-faces="false"
      data-width="200" data-max-rows="1"></div>
</div>

JAVASCRIPT / JQUERY

window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'XXXX,                        // App ID from the app dashboard
      channelUrl : '//WWW.XXXX.com', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });



    // Additional initialization code such as adding Event Listeners goes here
     // will be handled. 
  FB.Event.subscribe('auth.authResponseChange', function(response) {
    // Here we specify what we do with the response anytime this event occurs. 
    if (response.status === 'connected') {


      loginfunction();
    } else if (response.status === 'not_authorized') {

      FB.login(function(response) {},{scope: 'email'});
    } else {

      FB.login(function(response) {},{scope: 'email'});
    }
  });
  };

(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/en_GB/all.js#xfbml=1&appId=XXXXX";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));


function loginfunction() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function (response) {
        console.log(response);
/*I can see all the data here and the button also changes so I know that I am logged in */
        var data = 'action=signup&username=' + response.username + '&firstname=' + response.first_name + '&gender=' + response.gender + '&lastname=' + response.last_name + '&email=' + response.email + '&dob=' + "xxxx" + '&auth=facebook';
/*What's the point in passing all these parameters through ? only need to pass &auth=facebook and action=signup I guess the rest can be manipulated anyway so what's the point 
need to get them from PHP SDK (server side ajax call) */

        $.ajax({
            type: "POST",
            url: "actions/do_signup.php",
            data: data,
            beforeSend: function (html) {},
            success: function (html) {
                if (html == "success") {
                    window.location.replace("index.php");
                } else {}
            }
        });
    }, {
        scope: 'email'
    });
}

ありがとう

EDITは、PHPでのみ失敗したことを試みました

require('facebook.php');
$facebook = new Facebook( array (
    'appId'  => 'xxx',
    'secret' => 'xxxx',
    'cookie' => true
  )
);


if ($_REQUEST['act']=="fb")
{
//$next_url = $facebook->getLoginStatusUrl($params);

if ($facebook->getUser()) {
       $userProfile = $facebook->api('/me');
       $uid = $facebook->getUser();
       // do logic
       echo  $uid ;
       echo "ok";
    } else {
    echo "problem";
      $loginUrl = $facebook->getLoginUrl($params = array('scope' => user_birthday,read_stream,'redirect_uri' => 'http://xxxx/index.php?act=success'));
      header('Location:' . $loginUrl);

    }
}
else if ($_REQUEST['act']=="success")
{
  try{
      $_SESSION['fbAT'] = $facebook->getAccessToken();
    }catch(Exception $e){
      trigger_error("FB AccessToken: " . $e->getMessage());
    }    
$facebook->setAccessToken($_SESSION['fbAT']);

if ($facebook->getUser()) {
        $uid = $facebook->getUser();
       $userProfile = $facebook->api('/me');

       // do logic
       echo  $uid ;
       echo $userProfile;
       echo "ok";
    } else {
    $uid = $facebook->getUser();
    echo  $uid ;
    echo "still problem";


    }

私が試したいくつかのステップ:

  • サンドボックス モードが無効になっていて、アプリの ID とシークレットも確認​​しました...
  • ヘッダーを追加しようとしました: header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
  • Cookie を追加しました' => true
  • ajax を介さずに静的ページから呼び出してみてください。
  • Facebookの基本タブで使用されるのはWebサイトのみです
  • 高度なアプリの種類では、web に設定されています
  • 権限の下で、デフォルトのアクティビティは公開されています
  • fb_ca_chain_bundle.crt が、facebook.php が別のディレクトリを使用しようとしたのと同じディレクトリにあることを確認しました (私の php ファイルと同じです)。
    • アクセスを取得するために追加のスコープを使用して、PHP と getLoginUrl のみを試行します。
    • アクセストークンの取得と設定を試みる
4

2 に答える 2

4

window.fbAsyncInit で、cookie と oauth を true に設定しましたが、これはうまくいきました!

cookie:true,    
oauth : true.

あなたのphpにもあることを確認してください

cookie' => true.

これにより、php コードが JS と統合できるようになります。

于 2013-09-30T11:25:34.953 に答える