login with facebook

This commit is contained in:
vibol 2021-03-10 18:10:16 +07:00
parent 590adf5662
commit 7933898f57
8 changed files with 178 additions and 33 deletions

View File

@ -0,0 +1 @@
{"installed":{"client_id":"1051330489903-on15f3rmq3a1830f2cb3d7ber0duueqh.apps.googleusercontent.com","project_id":"deductive-tree-303007","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

View File

@ -33,6 +33,7 @@
android:name="io.flutter.embedding.android.SplashScreenDrawable" android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" android:resource="@drawable/launch_background"
/> />
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
@ -43,5 +44,25 @@
<meta-data <meta-data
android:name="flutterEmbedding" android:name="flutterEmbedding"
android:value="2" /> android:value="2" />
<!-- facebook app. -->
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<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="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application> </application>
</manifest> </manifest>

View File

@ -15,4 +15,15 @@
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar"> <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item> <item name="android:windowBackground">@android:color/white</item>
</style> </style>
<string name="app_name">Your App Name here.</string>
<!-- Replace "000000000000" with your Facebook App ID here. -->
<string name="facebook_app_id">2553407474960753</string>
<!--
Replace "000000000000" with your Facebook App ID here.
**NOTE**: The scheme needs to start with `fb` and then your ID.
-->
<string name="fb_login_protocol_scheme">fb2553407474960753</string>
</resources> </resources>

View File

@ -42,6 +42,7 @@
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>
<!-- Put me in the [my_project]/ios/Runner/Info.plist file --> <!-- Put me in the [my_project]/ios/Runner/Info.plist file -->
<!-- Google Sign-in Section --> <!-- Google Sign-in Section -->
<key>CFBundleURLTypes</key> <key>CFBundleURLTypes</key>
<array> <array>
@ -50,13 +51,49 @@
<string>Editor</string> <string>Editor</string>
<key>CFBundleURLSchemes</key> <key>CFBundleURLSchemes</key>
<array> <array>
<!-- TODO Replace this value: --> <string>1051330489903-on15f3rmq3a1830f2cb3d7ber0duueqh.apps.googleusercontent.com</string>
<!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID -->
<string>com.googleusercontent.apps.184261582386-t5mokji6qo3l77kf3m269onvelou1114</string>
</array> </array>
</dict> </dict>
</array> </array>
<!-- End of the Google Sign-in Section --> <!-- End of the Google Sign-in Section -->
<!-- Start key facebook -->
<key>CFBundleURLTypes</key>
<array>
<!--
<dict>
... Some other CFBundleURLTypes definition.
</dict>
-->
<dict>
<key>CFBundleURLSchemes</key>
<array>
<!--
Replace "000000000000" with your Facebook App ID here.
**NOTE**: The scheme needs to start with `fb` and then your ID.
-->
<string>fb2553407474960753</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<!-- Replace "000000000000" with your Facebook App ID here. -->
<string>2553407474960753</string>
<key>FacebookDisplayName</key>
<!-- Replace "YOUR_APP_NAME" with your Facebook App name. -->
<string>YOUR_APP_NAME</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
<!-- End key facebook -->
</dict> </dict>
</plist> </plist>

BIN
keyTool/keytool.jks Normal file

Binary file not shown.

View File

@ -5,17 +5,14 @@
// ignore_for_file: public_member_api_docs // ignore_for_file: public_member_api_docs
import 'dart:async'; import 'dart:async';
import 'dart:convert' show json;
import "package:http/http.dart" as http; import 'package:flutter_facebook_login/flutter_facebook_login.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart'; import 'package:google_sign_in/google_sign_in.dart';
GoogleSignIn _googleSignIn = GoogleSignIn( GoogleSignIn _googleSignIn = GoogleSignIn(
scopes: <String>[ clientId: "1051330489903-on15f3rmq3a1830f2cb3d7ber0duueqh.apps.googleusercontent.com",
'email', //clientId: "1051330489903-on15f3rmq3a1830f2cb3d7ber0duueqh.apps.googleusercontent.com"
'https://www.googleapis.com/auth/contacts.readonly',
],
); );
void main() { void main() {
@ -43,6 +40,7 @@ class SignInDemoState extends State<SignInDemo> {
setState(() { setState(() {
_currentUser = account; _currentUser = account;
}); });
if (_currentUser != null) { if (_currentUser != null) {
_handleGetContact(_currentUser); _handleGetContact(_currentUser);
} }
@ -54,28 +52,30 @@ class SignInDemoState extends State<SignInDemo> {
setState(() { setState(() {
_contactText = "Loading contact info..."; _contactText = "Loading contact info...";
}); });
final http.Response response = await http.get( // final http.Response response = await http.get(
Uri.parse('https://people.googleapis.com/v1/people/me/connections' // Uri.parse('https://people.googleapis.com/v1/people/me/connections'
'?requestMask.includeField=person.names'), // '?requestMask.includeField=person.names'),
headers: await user.authHeaders, // headers: await user.authHeaders,
); // );
if (response.statusCode != 200) { // if (response.statusCode != 200) {
setState(() { // print("Success ------> 200");
_contactText = "People API gave a ${response.statusCode} " // setState(() {
"response. Check logs for details."; // _contactText = "People API gave a ${response.statusCode} "
}); // "response. Check logs for details.";
print('People API ${response.statusCode} response: ${response.body}'); // });
return; // print('People API ${response.statusCode} response: ${response.body}');
} // return;
final Map<String, dynamic> data = json.decode(response.body); // }
final String namedContact = _pickFirstNamedContact(data); // final Map<String, dynamic> data = json.decode(response.body);
setState(() { // print("data $data");
if (namedContact != null) { // final String namedContact = _pickFirstNamedContact(data);
_contactText = "I see you know $namedContact!"; // setState(() {
} else { // if (namedContact != null) {
_contactText = "No contacts to display."; // _contactText = "I see you know $namedContact!";
} // } else {
}); // _contactText = "No contacts to display.";
// }
// });
} }
String _pickFirstNamedContact(Map<String, dynamic> data) { String _pickFirstNamedContact(Map<String, dynamic> data) {
@ -98,7 +98,9 @@ class SignInDemoState extends State<SignInDemo> {
Future<void> _handleSignIn() async { Future<void> _handleSignIn() async {
try { try {
await _googleSignIn.signIn(); await _googleSignIn.signIn().then((value){
print(value);
});
} catch (error) { } catch (error) {
print(error); print(error);
} }
@ -145,6 +147,57 @@ class SignInDemoState extends State<SignInDemo> {
} }
} }
//shower message for facebook
static final FacebookLogin facebookSignIn = new FacebookLogin();
String _message = 'Log in/out by pressing the buttons below.';
Future<Null> _login() async {
final FacebookLoginResult result =
await facebookSignIn.logIn(['email','public_profile']);
print(result.accessToken.token);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
final FacebookAccessToken accessToken = result.accessToken;
_showMessages('''
Logged in!
Token: ${accessToken.token}
User id: ${accessToken.userId}
Expires: ${accessToken.expires}
Permissions: ${accessToken.permissions}
Declined permissions: ${accessToken.declinedPermissions}
''');
break;
case FacebookLoginStatus.cancelledByUser:
_showMessages('Login cancelled by the user.');
break;
case FacebookLoginStatus.error:
_showMessages('Something went wrong with the login process.\n'
'Here\'s the error Facebook gave us: ${result.errorMessage}');
break;
}
}
Future<Null> _logOut() async {
await facebookSignIn.logOut();
_showMessages('Logged out.');
}
void _showMessages(String message) {
setState(() {
_message = message;
});
}
void _showMessage(String message) {
setState(() {
_message = message;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -153,7 +206,21 @@ class SignInDemoState extends State<SignInDemo> {
), ),
body: ConstrainedBox( body: ConstrainedBox(
constraints: const BoxConstraints.expand(), constraints: const BoxConstraints.expand(),
child: _buildBody(), child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildBody(),
Text(_message),
RaisedButton(
onPressed: _login,
child: Text('Log in'),
),
RaisedButton(
onPressed: _logOut,
child: new Text('Logout'),
),
],
),
)); ));
} }
} }

View File

@ -62,6 +62,13 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
flutter_facebook_login:
dependency: "direct main"
description:
name: flutter_facebook_login
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter

View File

@ -25,6 +25,7 @@ dependencies:
sdk: flutter sdk: flutter
google_sign_in: google_sign_in:
http: http:
flutter_facebook_login:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.