Getting Started with the Facebook SDK for Android
원문 링크 : https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/
4. Run the samples Try the sample projects, and add your Android key hash to your Facebook profile |
같이 압축되어있던 샘플 프로젝트들에 대한 설명이 살짝 나오네요.
Basic samples
- ProfilePictureSample: demonstrates non-logged-in usage of the profile picture control
- FriendPickerSample: demonstrates usage of the native friend picker to choose amongst the user's friends
- PlacePickerSample: demonstrates logged-in usage of the place picker control
Feature samples
- SessionLoginSample: demonstrates detailed login flow using the SDK
- JustRequestSample: demonstrates logged-in user making single and batched Facebook API requests
- BooleanOGSample: demonstrates publishing an Open Graph custom action type
- SwitchUserSample: demonstrates an approach to allow switching between multiple users
Complete samples
- HelloFacebookSample: an all-round sample that demonstrates profile access, status updates and photo uploading
- Scrumptious: demonstrates the use of login, requests, pickers, picture uploads, and Open Graph publishing
- Hackbook: another sample app demonstrating a selection of Graph API calls. Note that this sample is untouched from v2.0 of the SDK, and demonsrates the SDK's backward-compatibility.
Getting started 에 나와있는데로, Profile Picture sample 을 실행해봅니다. [Android Application] 으로 Run 해줍니다.
그러면, 이뮬레이터에 이렇게 실행이 되죠.
이번 스텝에서는 샘플앱을 실행시키는 것 보다는, keyhash 에 대한 설명을 더 강조하는 느낌이네요.
이런 간단한 앱을 실행할때는 상관없지만, 인증을 포함한 앱을 만들려면 좀 더 작업을 해줘야하죠.
모든 안드로이드 앱들은 서명이 되어야 한다는건데, 뭐.. 당연한거죠.
앞으로 만들 앱들의 신뢰성에 대한 보안측면의 체크를 위해 페이스북과 각 애플리케이션들의 키 해시를 등록해야 나중에 페이스북에서 확인을 할 수 있는거죠.
SDK 샘플이 이런 체크를 무시하고 빠르게 실행하려면 글로벌 페이스북 개발자 프로필에 키 해시를 추가할수도 있다고 하네요.
첫번째, 로컬 컴퓨터에 key hash 를 생성하려면 Android debug keystore 에 대해서 Java 의 keytool 유틸리티(콘솔 path에 있어야해요.)를 실행해야 합니다. OS X 에서 실행하고, user의 home 에 .android 디렉토리가 있다면 아래처럼 하면되요.
(보통은 user의 home 경로에 .android 디렉토리가 설정됩니다. 기본설정이라.. 아래 명령을 복사해서 콘솔에서 실행!)
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
이제 콘솔에서 만들어진 Key hash 를 Developer site 에 등록해보도록 하죠. 아래 링크에 접속합니다.
https://developers.facebook.com/
그리고 화면상단 네비게이션 오른쪽에 보이는 프로필이미지에서 settings 를 선택해줍니다.
이미 개발자로서 페이스북에 등록이 되있다면 상관없지만, 등록되어 있지 않은경우, 이런 화면이 뜰거에요.
등록해줍니다.
Getting started 에 있는 스크린 샷과 제 화면은 조금 다르게 뜨네요. 별로 상관은 없는 부분이니...
[Developer Settings] > [Sample App Settings] 를 선택하고, Android Key Hash 부분에 위에서 만든 Key hash 를 넣어줍니다. 여러 컴퓨터에서 개발하는 경우에도 key hash 를 여러개 추가할 수 있습니다.
만약 샘플앱을 실행하다가 key hash 때문에 에러가 발생하는 경우에 대한 부연 설명들도 있네요.
(이 형들... 친절해졌어요...)
- A native Login Dialog is displayed but after accepting the permissions you are still in a logged out state. The logcat also contains an exception similar to this:
12-20 10:23:24.507: W/fb4a:fb:OrcaServiceQueue(504): com.facebook.orca.protocol.base.ApiException: remote_app_id does not match stored id
- A non-native Login Dialog is displayed that includes an error message at the top: ''..App is Misconfigured for facebook login...''.
이런 경우들에 아래와 같은 코드로 key hash 를 체크해 본 후, 위에서 한 것 처럼, developer site 에 추가를 해주면됩니다.
그럼, 로그인 할때, 인증과 관련해 key hash 에러는 나지 않겠죠.
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
12-20 10:47:37.747: D/KeyHash:(936): 478uEnKQV+fMQT8Dy4AKvHkYibo=
5. Create a Facebook App Create a new Facebook app, get its ID and associate your Android key hash with it |
이번에는 만들려는 앱을 페이스북 개발자 페이지에 등록/생성하는 스텝이네요.
App Dashboard 페이지로 갑니다. Developer site 에서 [Apps] 를 클릭해도 갈 수 있어요.
화면 오른쪽에 보이는 [+ 새 앱 만들기] 또는.. [+ Create New App] 을 클릭합니다.
앱 이름과 정보를 넣어주고 [계속하기]/[Continue]를 눌러주세요.
이제 이런 화면을 볼 수 있습니다.
아래쪽에 보이는 [네이티브 Android 앱]/[Native Android App] 에 [4]스텝에서 만든 Key hash 를 넣어주고 변경 내용을 저장해줍니다.
이 다음 스텝이 어마어마하네 길군요.
그래서 이건 여기서 살짝 끊고.. 다음 포스트에서...
'Android Tutorial > Facebook(페이스북)' 카테고리의 다른 글
[Facebook] Scrumptious Tutorial (0) | 2013.01.21 |
---|---|
[3] Getting Started with the Facebook SDK for Android (4) | 2013.01.16 |
[1] Getting Started with the Facebook SDK for Android (0) | 2013.01.15 |
What’s New in Facebook SDK 3.0 for Android (0) | 2013.01.15 |
[Facebook] Android Tutorial (0) | 2012.02.20 |