SORU
27 Kasım 2008, PERŞEMBE


Facebook Bağlayın ve ASP.NET

Adım başı kimlik doğrulama bakış burada bulunan 8 yapıyorum: http://wiki.developers.facebook.com/index.php/How_Connect_Authentication_Works

Özellikle, kullanıcı, Facebook üzerinden facebook Connect oturum ve web oturumu oluşturuldu. Nasıl facebook geliştirici toolkit v2 kullanırım.0 (açıklık) kullanıcı hakkında bilgi almak için. Örneğin, kullanıcının adını ve soyadını almak istiyorum.

Belgelerinde örnek bu değil facebook Uygulamaları, yöneliktir.

Güncelleme

Son zamanlarda Facebook Graph API yayınladı. Facebook Connect kullanarak bir uygulama korumak sürece, en son API kontrol etmelisiniz: http://developers.facebook.com/docs/

CEVAP
15 Aralık 2008, PAZARTESİ


Bir sürü sorun, bir kullanıcı Facebook ile giriş bağlandıktan sonra sunucu tarafında arama yapmak için nasıl bulmaktan vardı. Anahtar Facebook başarılı bir giriş var bir kere javascript ayarlar istemci kurabiye Bağlayın. Bu çerez değerleri sunucuda API çağrıları gerçekleştirmek için kullanın.

Kafa karıştırıcı kısmı PHP örnek de serbest bıraktılar bakıyordu. Sunucu tarafı kendi API otomatik olarak bu çerez değerleri okuma ve giriş yapan kullanıcı adına isteklerini yapmak için hazır API nesne kurma ilgilenir.

İşte size bir örnek kullanıcı Facebook ile login olduktan sonra sunucuda Facebook Toolkit kullanarak Bağlayın.

Sunucu kodu:

API api = new API();
api.ApplicationKey = Utility.ApiKey();
api.SessionKey = Utility.SessionKey();
api.Secret = Utility.SecretKey();
api.uid = Utility.GetUserID();

facebook.Schema.user user = api.users.getInfo();
string fullName = user.first_name   " "   user.last_name;

foreach (facebook.Schema.user friend in api.friends.getUserObjects())
{
   // do something with the friend
}

Yarar.cs

public static class Utility
{
    public static string ApiKey()
    {
        return ConfigurationManager.AppSettings["Facebook.API_Key"];
    }

    public static string SecretKey()
    {
        return ConfigurationManager.AppSettings["Facebook.Secret_Key"];
    }

    public static string SessionKey()
    {
        return GetFacebookCookie("session_key");
    }

    public static int GetUserID()
    {
        return int.Parse(GetFacebookCookie("user"));
    }

    private static string GetFacebookCookie(string name)
    {
        if (HttpContext.Current == null)
            throw new ApplicationException("HttpContext cannot be null.");

        string fullName = ApiKey()   "_"   name;
        if (HttpContext.Current.Request.Cookies[fullName] == null)
            throw new ApplicationException("Could not find facebook cookie named "   fullName);
        return HttpContext.Current.Request.Cookies[fullName].Value;
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • SuicideSheeep

    SuicideSheee

    8 Ocak 2012
  • SuperPrincessjo

    SuperPrinces

    1 EKİM 2010
  • wwjoshdo

    wwjoshdo

    25 Mayıs 2009