I'm trying to authenticate with faceboook and twitter , & done with setUp part of facebook Developr console and implemented facebook login method to dart code but why there is occurring an error at
facebookLogin.logInWithReadPermission.
but I'm following the dart packages site facebook_sign_in Plugin
Code:
Future<FirebaseUser> signInWithFacebook()async{
FacebookLogin facebookLogin = new FacebookLogin();
final FacebookLoginResult result = await facebookLogin.logInWithReadPermissions(['email']);
}
Twitter auth method
Future<bool> signInWithTwitterAccount()async{
setState(() {
isLoading=true;
});
try{
TwitterLogin twitterLogin = new TwitterLogin(
consumerKey: consumerApiKey,
consumerSecret: consumerSecretApiKey
);
TwitterLoginResult _twitterLoginResult = await twitterLogin.authorize();
TwitterSession _currentUserTwitterSession = _twitterLoginResult.session;
AuthCredential authCredential = TwitterAuthProvider.getCredential(
authToken: _currentUserTwitterSession.token,
authTokenSecret: _currentUserTwitterSession.secret
);
AuthResult result = await auth.signInWithCredential(authCredential);
if(result.user== null)
return false;
return true;
}catch(error){
Fluttertoast.showToast(msg: "Log in Error at :$error");
return false;
}
}
Twitter SignIn Button:
Widget build(BuildContext context){
return Scaffold(
body: Center(
child: FlatButton(
child: Text(Login with Twitter),
onPressed: () async{
bool res= await signInWithGoogleAccount();
if(!res)
{ setState(() {
isLoading=false;
});
Fluttertoast.showToast(msg: "Login failed");
}else{
setState(() {
isLoading=false;
});
Fluttertoast.showToast(msg: "Logged in successfully");
Navigator.of(context).pushReplacementNamed('/homepage');
}
},
)
)
);
}
Exception ,when clicked twitter sign in button:
E/Twitter ( 7270): Invalid json: <?xml version="1.0" encoding="UTF-8"?><errors><error code="415">Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings</error></errors>
E/Twitter ( 7270): com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
E/Twitter ( 7270): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:226)
E/Twitter ( 7270): at com.twitter.sdk.android.core.models.SafeListAdapter$1.read(SafeListAdapter.java:45)
E/Twitter ( 7270): at com.twitter.sdk.android.core.models.SafeMapAdapter$1.read(SafeMapAdapter.java:45)
E/Twitter ( 7270): at com.google.gson.Gson.fromJson(Gson.java:927)
E/Twitter ( 7270): at com.google.gson.Gson.fromJson(Gson.java:892)
E/Twitter ( 7270): at com.google.gson.Gson.fromJson(Gson.java:841)
E/Twitter ( 7270): at com.google.gson.Gson.fromJson(Gson.java:813)
E/Twitter ( 7270): at com.twitter.sdk.android.core.TwitterApiException.parseApiError(TwitterApiException.java:110)
E/Twitter ( 7270): at com.twitter.sdk.android.core.TwitterApiException.readApiError(TwitterApiException.java:95)
E/Twitter ( 7270): at com.twitter.sdk.android.core.TwitterApiException.<init>(TwitterApiException.java:43)
E/Twitter ( 7270): at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
E/Twitter ( 7270): at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
E/Twitter ( 7270): at android.os.Handler.handleCallback(Handler.java:794)
E/Twitter ( 7270): at android.os.Handler.dispatchMessage(Handler.java:99)
E/Twitter ( 7270): at android.os.Looper.loop(Looper.java:176)
E/Twitter ( 7270): at android.app.ActivityThread.main(ActivityThread.java:6635)
E/Twitter ( 7270): at java.lang.reflect.Method.invoke(Native Method)
E/Twitter ( 7270): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
E/Twitter ( 7270): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
E/Twitter ( 7270): Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
E/Twitter ( 7270): at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:385)
E/Twitter ( 7270): at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:215)
E/Twitter ( 7270): ... 18 more
E/Twitter ( 7270): Failed to get request token
E/Twitter ( 7270): com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 403
E/Twitter ( 7270): at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
E/Twitter ( 7270): at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
E/Twitter ( 7270): at android.os.Handler.handleCallback(Handler.java:794)
E/Twitter ( 7270): at android.os.Handler.dispatchMessage(Handler.java:99)
E/Twitter ( 7270): at android.os.Looper.loop(Looper.java:176)
E/Twitter ( 7270): at android.app.ActivityThread.main(ActivityThread.java:6635)
E/Twitter ( 7270): at java.lang.reflect.Method.invoke(Native Method)
E/Twitter ( 7270): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
E/Twitter ( 7270): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
I/zygote64( 7270): Do partial code cache collection, code=121KB, data=74KB
I/zygote64( 7270): After code cache collection, code=121KB, data=74KB
I/zygote64( 7270): Increasing code cache capacity to 512KB
E/Twitter ( 7270): Authorization completed with an error
E/Twitter ( 7270): com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
E/Twitter ( 7270): at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:94)
E/Twitter ( 7270): at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:191)
E/Twitter ( 7270): at com.twitter.sdk.android.core.Callback.onResponse(Callback.java:42)
E/Twitter ( 7270): at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
E/Twitter ( 7270): at android.os.Handler.handleCallback(Handler.java:794)
E/Twitter ( 7270): at android.os.Handler.dispatchMessage(Handler.java:99)
E/Twitter ( 7270): at android.os.Looper.loop(Looper.java:176)
E/Twitter ( 7270): at android.app.ActivityThread.main(ActivityThread.java:6635)
E/Twitter ( 7270): at java.lang.reflect.Method.invoke(Native Method)
E/Twitter ( 7270): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
E/Twitter ( 7270): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
I/Toast ( 7270): Show toast from OpPackageName:com.company_name.project, PackageName:com.company_name.project
E/SpannableStringBuilder( 7270): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
E/SpannableStringBuilder( 7270): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
W/ContentCatcher( 7270): Failed to notify a WebView
W/ResourceType( 7270): No package identifier when getting name for resource number 0x00000000
Seems logInWithReadPermission method is not present in latest release. As seen in their repository: https://github.com/roughike/flutter_facebook_login/blob/master/lib/flutter_facebook_login.dart
You can try to login as shown in example code, which uses "logIn" function instead of logInWithPermission, check out repository example here
import 'dart:async';
import 'package:flutter_facebook_login/flutter_facebook_login.dart';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
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']);
switch (result.status) {
case FacebookLoginStatus.loggedIn:
final FacebookAccessToken accessToken = result.accessToken;
_showMessage('''
Logged in!
Token: ${accessToken.token}
User id: ${accessToken.userId}
Expires: ${accessToken.expires}
Permissions: ${accessToken.permissions}
Declined permissions: ${accessToken.declinedPermissions}
''');
break;
case FacebookLoginStatus.cancelledByUser:
_showMessage('Login cancelled by the user.');
break;
case FacebookLoginStatus.error:
_showMessage('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();
_showMessage('Logged out.');
}
void _showMessage(String message) {
setState(() {
_message = message;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Plugin example app'),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(_message),
new RaisedButton(
onPressed: _login,
child: new Text('Log in'),
),
new RaisedButton(
onPressed: _logOut,
child: new Text('Logout'),
),
],
),
),
),
);
}
}
User contributions licensed under CC BY-SA 3.0