-
07/09 페이스 북 로그인 1카테고리 없음 2021. 7. 9. 13:09
https://developers.facebook.com/docs/unity/gettingstarted
https://developers.facebook.com/docs/development/create-an-app
앱 만들기 버튼 클릭
비밀번호 입력 후 완료
설정 -> 기본설정
앱 ID, 시크릿 코드 확인
https://developers.facebook.com/docs/unity/downloadssdk 다운로드
유니티 프로젝트 생성
플랫폼 설정 안드로이드로
sdk 임포트
sdk를 임포트하면 자동으로 창이 생김 메인메뉴씬 열기 MainMenu 씬 fb.Init
클래식 로그인 클릭
클래식 로그인 창 파인드 액세스 토큰 클릭
권한 부여 클릭
제너레이트 클릭
수락 클릭
빌드세팅에 씬 추가
빌드세팅에 메인메뉴와 로그뷰 추가 생성된 액세스 토큰 유니티에 유저 액세스 토큰에 입력
센드 석세스 클릭
로그 클릭
페이스북 -> 에디트 세팅 -> 인스펙터
앱 name, id 적기
씬 전부 넣기
메인메뉴를 맨 위로
min level을 21 이상으로 설정
패키지네임을 페이스북 앱 네임으로 설정
유니티에서 Edit -> Preference -> External Tools의 SDK경로 확인
(유니티 기본으로 되어 있는지)
유니티 기본이라면 check 해제
안드로이드 스튜디오 열기
config -> sdk manager
Android SDK Location 복사
유니티에서 SDK 경로 설정
openSSL설치
https://code.google.com/archive/p/openssl-for-windows/downloads
Google Code Archive - Long-term storage for Google Code Project Hosting.
code.google.com
환경변수 설정하고 재시작
페이스북 -> 에디트 세팅 -> 인스펙터
key hash나오는 것 확인
빌드하고 녹스에서 돌아가는 지 확인
페이스북 개발자 페이지 -> 설정 -> 기본설정 -> 플랫폼 추가
플랫폼 추가
패키지이름, 클래스 이름, 해시 키를 입력
카테고리 설정 후 저장
샘플 씬에서 버튼 생성
빈오브젝트 생성
코드 작성
빈오브젝트에 코드 추가
App.cs
using Facebook.Unity; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class App : MonoBehaviour { public Button btnFacebook; List<string> perms = new List<string>() { "public_profile", "email" }; private void Awake() { if (!FB.IsInitialized) { // Initialize the Facebook SDK FB.Init(InitCallback, OnHideUnity); } else { // Already initialized, signal an app activation App Event FB.ActivateApp(); } } private void InitCallback() { if (FB.IsInitialized) { // Signal an app activation App Event FB.ActivateApp(); // Continue with Facebook SDK // ... } else { Debug.Log("Failed to Initialize the Facebook SDK"); } } private void OnHideUnity(bool isGameShown) { if (!isGameShown) { // Pause the game - we will need to hide Time.timeScale = 0; } else { // Resume the game - we're getting focus again Time.timeScale = 1; } } private void AuthCallback(ILoginResult result) { if (FB.IsLoggedIn) { // AccessToken class will have session details var aToken = Facebook.Unity.AccessToken.CurrentAccessToken; // Print current access token's User ID Debug.Log(aToken.UserId); // Print current access token's granted permissions foreach (string perm in aToken.Permissions) { Debug.Log(perm); } } else { Debug.Log("User cancelled login"); } } // Start is called before the first frame update void Start() { btnFacebook.onClick.AddListener(() => { FB.LogInWithReadPermissions(perms, AuthCallback); Debug.Log("버튼 클릭"); }); } // Update is called once per frame void Update() { } }
빌드 후 녹스에서 동작 확인