flutter

(구)Twitter (현)X 로그인 구현 - Flutter

이나주니 2024. 8. 9. 11:50
반응형

오늘은 플러터를 이용한 트위터 로그인 기능을 구현해 보겠습니다.

 

https://firebase.flutter.dev/docs/auth/social/#twitter

 

Social Authentication | FlutterFire

This page is archived and might not reflect the latest version of the

firebase.flutter.dev

공식 사이트

 

1. 트위터 개발자 계정 만들기

https://developer.x.com/en

 

Use Cases, Tutorials, & Documentation

Publish & analyze posts, optimize ads, & create unique customer experiences with the X API, X Ads API, & X Embeds.

developer.x.com

 

2. 개발자 포털 

https://developer.x.com/en/docs/twitter-api/getting-started/getting-access-to-the-twitter-api

 

Getting access to the Twitter API

Did someone say … cookies? X and its partners use cookies to provide you with a better, safer and faster service and to support our business. Some cookies are necessary to use our services, improve our services, and make sure they work properly. Show mor

developer.x.com

 

가입 선택

 

Developer agreement & policy 정보 입력 (영어로) - 250자 이상이어야함

 

제출후 아래와 같은 페이지 이동

 

스크롤을 좀 내리면 하단에 Set UP 선택

 

필요한 정보 입력 후 save

 

 

Ouath 2.0 클라이언트 ID와 비밀번호 생성

 

 


 

이제 Pub.dev 에 접근

https://pub.dev/packages/twitter_login

 

twitter_login | Flutter package

Flutter Twitter Login Plugin. Library for login with Twitter APIs OAuth service

pub.dev

 

패키지 추가

 

이후 먼저 ios info.plist

 

안드로이드 manifest

<meta-data
    android:name="flutterEmbedding"
    android:value="2" />

 

 

주의 할점:

1. 아래의 코드 제거

android:host="gizmos"

 

2. activity 를 새로 만들지 말고 기존에 있는 activity 에 intent-filter 추가해주기

  <intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="앱이름" /> <!-- host is option -->
</intent-filter>

 

셋팅완료

 

이제 코드 를 입력해보자

OutlinedButton(
onPressed: () async {
final twitterLogin = TwitterLogin(
apiKey: '트위터 Developer Potal api key 입력',
apiSecretKey: '트위터 Developer Potal api secret key 입력',
redirectURI: '콜백 URL',
);

final authResult = await twitterLogin.login();
switch (authResult.status) {
case TwitterLoginStatus.loggedIn:
// success
break;
case TwitterLoginStatus.cancelledByUser:
// cancel
break;
case TwitterLoginStatus.error:
// error
break;
}
},

 

만약 키를 모른다면 재 생성 Regenerate 선택 하면 재생성후 조회 가능

 

반응형