$ Facebook-> getSession () örnek kod null döndürür.

3 Cevap php

example code for the Facebook API Ben bir null session nesnesi olsun, ve ben kod Yorumu veren null olmayan bir nesneyi almak gerekir Koşu. What am I doing wrong?

Diğer bir deyişle, benim index.php örnek kodun gösterdiği bu fragmanı "no session" benim tarayıcıda http://apps.facebook.com/my_app gittiğinizde:

<?php

require './facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId' => '...', // actual value replaced by '...' for this post
  'secret' => '...', // actual value replaced by '...' for the post
  'cookie' => true,
));

// We may or may not have this data based on a $_GET or $_COOKIE based session.
//
// If we get a session here, it means we found a correctly signed session using
// the Application Secret only Facebook and the Application know. We dont know
// if it is still valid until we make an API call using the session. A session
// can become invalid if it has already expired (should not be getting the
// session back in this case) or if the user logged out of Facebook.
$session = $facebook->getSession();

if ($session) {
  echo "session ok";
}
else {
  echo "no session";
}


?>

Not: benim sunucu index.php ve facebook.php aynı klasörde içinde.

3 Cevap

Henüz app bağlantılı mı?

if ($session) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}
 <?php if ($me): ?>
<a href="<?php echo $logoutUrl; ?>">
<img src="http://static.ak.fbcdn.net/rsrc.php/z2Y31/hash/cxrz4k7j.gif">
</a>
<?php else: ?>
<div>
Using JavaScript &amp; XFBML: <fb:login-button></fb:login-button>
</div>
<div>
Without using JavaScript &amp; XFBML:
<a href="<?php echo $loginUrl; ?>">
<img src="http://static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">
</a>
</div>
<?php endif ?>

Verdiğiniz linke alınan Kodu.

http://forum.developers.facebook.net/viewtopic.php?pid=267627 at Mesaja 8. kontrol edin

Bu benim için çalıştı. Eğer kullanıcı "standardcombo" Teşekkür ederim.

Ben size kolaylık için buraya kopyaladığınız.

  1. "Benim Uygulamalar" geliştirici sayfasına git
  2. Lütfen uygulamayı seçin ve 'Ayarları Düzenle'
  3. Gelişmiş> Göçler> "Canvas (beta) için OAuth 2.0" Enable

Bunu henüz cevap kazanılmış ettik emin değilim, ama burada ben bu kendimi çalışan bulundu budur. Kullanıcı facebook oturum açmış olsa bile, bir oturum almak için deneyin ilk kez boş olacaktır. Ben buldum örnek başvuru formunda bir giriş düğmesi koyar - Bunu yaparsanız, ancak, daha sonra kullanıcı bile zaten facebook giriş yaptığınız butonuna tıklamanız gerekir. Bunlar yeniden sorulması değil, ama fazladan bir kullanıcı eylemi var.

Yani benim app ve ben forumlarda bulunan çeşitli başkaları için çalışmıştır ne sadece giriş URL'ye yönlendirmek. (Eğer url incelemek, kendi parametrelerinden biri "return_session = 1" dir.) Bu geri geldiğinde, o zaman bir oturuma sahip olacak ve normal devam edebilirsiniz.

Ben bir uygulama simgesi yoksa ama benim uygulamada, o zaman ben de o oturuma alamayan, bu yüzden ilk bir uygulama simgesi almak zorunda. Bir uygulama simge almak için http://forum.developers.facebook.com/viewtopic.php?id=56789 adlı mükemmel açıklaması, (dördüncü yazı aşağı yaklaşık) 7 Mayıs 2010 tarihinde dynamoman gelen mesaja bakmak.

Ben koştum bir şey olursa ben doğrulama "sonraki" sayfası söylemek nerede, o tuval yapılandırılmış sayfaya gider. Yerine üç ayrı sayfaları Yani, sadece iki tane var, ve tuval geri URL içeri bulunuyor hangisi devlet işlemek zorunda

Benim asıl kod bu yüzden doğrudan uygulanabilir olmayan bir çerçeve içinde olduğunu; bir algoritma olarak, o:

landing page:
    if the facebook api token is not loaded,
        redirect to the authorization url
    try to load the user id // to validate that the session
    if the user id is not loaded,
        redirect to the loginurl from the facebook api
    // if it reaches here, then we have both an api token and a session

authorization page:
    get authorization token // see the post for how to do that
    redirect back to the page configured as the canvas url

Orada daha iyi bir yolu olabilir, ve ben kendimi daha bu daha aşina birisi daha iyi bir çözüm, ya sonrası genel kod olabilir emin değilim olabilir.