Skip to content

Instantly share code, notes, and snippets.

@ezaurum
Created December 10, 2015 14:58
Show Gist options
  • Save ezaurum/80c7b509fe5d6458e831 to your computer and use it in GitHub Desktop.
Save ezaurum/80c7b509fe5d6458e831 to your computer and use it in GitHub Desktop.
facebook login script
using System.Collections.Generic;
using Facebook.Unity;
using UnityEngine;
/// <summary>
/// 페이스북 관련 스크립트
/// </summary>
public class FacebookScript : MonoBehaviour
{
private bool _fb;
private List<string> _permissions;
void Start()
{
// 퍼미션 지정
_permissions = new List<string> { "public_profile", "email", "user_friends" };
// 페이스북 초기화
FB.Init(OnFacebookInitComplete, OnHideUnity);
}
void OnGUI()
{
if (_fb)
{
LogInWithReadPermissions();
_fb = false;
}
}
/// <summary>
/// 페북 로그인 버튼 누를 때
/// </summary>
public void LoginFB()
{
#if UNITY_EDITOR
// 유니티 에디터일 때는 레거시 GUI를 호출한다.
_fb = true;
#else
LogInWithReadPermissions();
#endif
}
/// <summary>
/// 퍼미션을 지정하고 로그인을 시킨다.
/// </summary>
private void LogInWithReadPermissions()
{
FB.LogInWithReadPermissions(_permissions, OnResponseLoginResult);
}
/// <summary>
/// 로그인 결과
/// </summary>
/// <param name="result"></param>
private void OnResponseLoginResult(ILoginResult result)
{
// 페이스북 정보로 할 수 있는 처리를 해 본다.
Debug.Log("accessToken " + result.AccessToken.TokenString);
}
/// <summary>
/// 게임 활성화 상태가 변할 때 - 페이스북 팝업이 뜨거나 닫힐때.
/// </summary>
/// <param name="isunityshown"></param>
private void OnHideUnity(bool isunityshown)
{
Debug.Log("unity hide is " + isunityshown);
}
/// <summary>
/// 페이스북 초기화가 끝났을 때
/// </summary>
private void OnFacebookInitComplete()
{
Debug.Log("facebook initialized. FB.Init() called with " + FB.AppId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment