We tried a million solutions and ways to connect our app with Twitter API
we want to create a login page that will direct the user to his timeline, but all we got is the TwitterDevoloperAccount that I used. Also, we could not get the user credential.
There’s really not enough information here for anyone to help you. Can you share the code? What is the error? What is happening? Without detailed code and config details I don’t think we can help.
1 Like
The error is that the user credential doesn’t return to the code correctly, I am trying to use it so I can show the timeline for each user logged in.
This is the main:
import 'dart:math';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_twitter_login/flutter_twitter_login.dart' ;
import 'package:firebase_auth/firebase_auth.dart' as auth;
import 'package:twitter_kit/twitter_kit.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final Future<FirebaseApp> _fbApp = Firebase.initializeApp();
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: FutureBuilder(
future: _fbApp ,
builder: (context , snapshot) {
if(snapshot.hasError){
print("error");
return Text("Errorrrrrrrrr!!!!!!!!!!!!!!!!");
} else if(snapshot.hasData){
return MyHomePage(title: "My amazing GP");
}else{
return Center(
child: CircularProgressIndicator(),
);
}
},
),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
DatabaseReference _testRef = FirebaseDatabase.instance.reference().child("test");
_testRef.set("Hello World!${Random().nextInt(100)}");
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
Future<auth.User> loginWithTwitter() async {
var twitterLogin = new TwitterLogin(
consumerKey: '&&&',
consumerSecret: '&&&',
);
final auth.FirebaseAuth _auth = auth.FirebaseAuth.instance;
final TwitterLoginResult result = await twitterLogin.authorize();
switch (result.status) {
case TwitterLoginStatus.loggedIn:
var session=result.session;
final auth.AuthCredential credential= TwitterAuthProvider.credential(accessToken: session.token, secret: session.secret);
auth.User firebaseUser=(await _auth.signInWithCredential(credential)).user;
print("twitter sign in"+firebaseUser.toString());
break;
case TwitterLoginStatus.cancelledByUser:
break;
case TwitterLoginStatus.error:
break;
}
return null;
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: loginWithTwitter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
And this is the dependencies file:
a screenshot for the output:
Those errors all appear to be internal (and the error about Bluetooth is definitely nothing to do with the Twitter API). Can you see anything at the HTTP network request level inside of your logs? Anything that specifically refers to Twitter OAuth calls?
system
Closed
#5
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.