Skip to content

Instantly share code, notes, and snippets.

@ado3s
Created December 25, 2016 17:02
Show Gist options
  • Save ado3s/8d2dffe1c0d34028ea3dd43d81e4553a to your computer and use it in GitHub Desktop.
Save ado3s/8d2dffe1c0d34028ea3dd43d81e4553a to your computer and use it in GitHub Desktop.
【Unity】Facebook SDK のログイン処理
using Facebook.Unity;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SampleView : MonoBehaviour
{
void Awake()
{
FBInitialize();
}
void Start()
{
var btn = transform.FindChild("FBLoginButton").GetComponent<Button>();
btn.onClick.AddListener(Login);
}
// Login処理
private void Login()
{
var list = new List<string> { "public_profile", "email", "user_friend" };
FB.LogInWithReadPermissions(list, result =>
{
var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
var userId = aToken.UserId;
Debug.Log(string.Format("Facebook UserId : {0}", userId));
// これでユーザID取ってこれる。
// んで、このユーザIDをキーにDBから情報とってくるてな感じ
// のソースをここに書けばおk
});
}
// Facebook初期化
private void FBInitialize()
{
if (!FB.IsInitialized)
{
FB.Init(() =>
{
if (FB.IsInitialized)
FB.ActivateApp();
},
isShown =>
{
// ゲームなんかの場合はここでゲームを止めたり
});
}
else
{
FB.ActivateApp();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment