Created
December 25, 2016 17:02
-
-
Save ado3s/8d2dffe1c0d34028ea3dd43d81e4553a to your computer and use it in GitHub Desktop.
【Unity】Facebook SDK のログイン処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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