Commit 1a249a37 authored by Administrator's avatar Administrator

failing with strava auth"

parent 0e46668d
import 'package:flutter/material.dart';
import 'package:encrateia/models/athlete.dart';
import 'package:scoped_model/scoped_model.dart';
import 'strava/strava_login2.dart';
class EditAthleteScreen extends StatelessWidget {
@override
......@@ -39,7 +40,13 @@ class EditAthleteScreen extends StatelessWidget {
children: <Widget>[
FlatButton(
child: const Text('CONNECT TO STRAVA'),
onPressed: () {},
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StravaFlutterPage()),
);
},
)
],
))
......
import 'package:flutter/material.dart';
import 'package:encrateia/secrets/secrets.dart';
import 'package:strava_flutter/strava.dart';
import 'package:strava_flutter/Models/detailedAthlete.dart';
class StravaLogin extends StatefulWidget {
final String title = "Strava Login";
StravaLogin() {}
@override
_StravaLoginState createState() => _StravaLoginState();
}
class _StravaLoginState extends State<StravaLogin> {
bool isAuthOk = false;
Strava strava;
DetailedAthlete stravaAthlete;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
loginToStrava();
return WillPopScope(
onWillPop: () {
Navigator.pop(context, true);
},
child: Scaffold(
appBar: AppBar(title: Text('Create Athlete')),
body: Container(child:
Text("isAuthOk ${isAuthOk} \n"
"stravaAthlete ${stravaAthlete}"))
)
);
}
loginToStrava() async {
strava = Strava(true, secret);
final prompt = 'auto';
final auth = await strava.oauth(
clientId,
'activity:write,activity:read_all,profile:read_all,profile:write',
secret,
prompt);
final athlete = await strava.getLoggedInAthlete();
setState(() {
isAuthOk = auth;
stravaAthlete = athlete;
});
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:encrateia/secrets/secrets.dart';
import 'package:strava_flutter/strava.dart';
import 'package:strava_flutter/Models/activity.dart';
import 'package:strava_flutter/Models/club.dart';
import 'package:strava_flutter/Models/detailedAthlete.dart';
import 'package:strava_flutter/Models/gear.dart';
import 'package:strava_flutter/Models/runningRace.dart';
import 'package:strava_flutter/Models/stats.dart';
import 'package:strava_flutter/Models/summaryAthlete.dart';
import 'package:strava_flutter/Models/zone.dart';
Strava strava;
class StravaFlutterPage extends StatefulWidget {
StravaFlutterPage({Key key}) : super(key: key);
final String title = "Page Title";
@override
_StravaFlutterPageState createState() => _StravaFlutterPageState();
}
class _StravaFlutterPageState extends State<StravaFlutterPage> {
@override
void initState() {
setState(() {});
super.initState();
}
void exampleStrava() {
example(secret);
}
///
/// Example of dart code to use Strava API
///
/// set isInDebug to true in strava init to see the debug info
void example(String secret) async {
bool isAuthOk = false;
final strava = Strava(true, secret);
final prompt = 'auto';
isAuthOk = await strava.oauth(
clientId,
'activity:write,activity:read_all,profile:read_all,profile:write',
secret,
prompt);
if (isAuthOk) {
// Get the zones related to the logged athlete
Zone _zone = await strava.getLoggedInAthleteZones();
if (_zone.fault.statusCode != 200) {
print(
'Error in getLoggedInAthleteZones ${_zone.fault.statusCode} ${_zone.fault.message}');
} else {
_zone.infoZones.zones.forEach(
(zone) => print('getLoggedInAthleteZones ${zone.min} ${zone.max}'));
}
// Create an new activity
String _startDate = '2019-02-18 10:02:13';
DetailedActivity _newActivity = await strava.createActivity(
'Test_Strava_Flutter', 'ride', _startDate, 3600,
distance: 1555, description: 'This is a strava_flutter test');
if (_newActivity.fault.statusCode != 201) {
print(
'Error in createActivity ${_newActivity.fault.statusCode} ${_newActivity.fault.message}');
} else {
print('createActivity ${_newActivity.name}');
}
// Type of expected answer:
// {"id":25707617,"username":"patrick_ff","resource_state":3,"firstname":"Patrick","lastname":"FF",
// "city":"Le Beausset","state":"Provence-Alpes-Côte d'Azur","country":"France","sex":null,"premium"
DetailedAthlete _athlete = await strava.getLoggedInAthlete();
if (_athlete.fault.statusCode != 200) {
print(
'Error in getloggedInAthlete ${_athlete.fault.statusCode} ${_athlete.fault.message}');
} else {
print('getLoggedInAthlete ${_athlete.firstname} ${_athlete.lastname}');
}
// Type of expected answer
// {"biggest_ride_distance":156733.0,"biggest_climb_elevation_gain":null,"recent_ride_totals":{"count":2,"distance":111427.7001953125,
// "moving_time":17726,"elapsed_time":23181,"elevation_gain":1354.5838375091553,"achievement_count":0},"recent_run_to
Stats _stats = await strava.getStats(_athlete.id);
if (_stats.fault.statusCode != 200) {
print(
'Error in getStats ${_stats.fault.statusCode} ${_stats.fault.message}');
} else {
print(
'getStats ${_stats.ytdRideTotals.distance} ${_stats.ytdRideTotals.elevationGain} ${_stats.allSwimTotals.distance}');
}
// A long list of races per city
// Starting by Walt Disney World Marathon
List<RunningRace> _listRunningRaces =
await strava.getRunningRaces('2019');
if ((_listRunningRaces == null) ||
(_listRunningRaces[0].fault.statusCode != 200)) {
print(
'Error in getRunningRaces: ${_listRunningRaces[0].fault.statusCode} ${_listRunningRaces[0].fault.message}');
} else {
print('getRunningRaces ${_listRunningRaces[0].name}');
}
// id corresponding to BMW Berlin Marathon 29th Sept 2019
RunningRace _race = await strava.getRunningRaceById('2724');
if (_race.fault.statusCode != 200) {
print(
'Error in getRunningRaceById ${_race.fault.statusCode} ${_race.fault.message}');
} else {
print('getRunningRaceById $_race');
}
// Change weight of the loggedAthlete in profile (in kg)
DetailedAthlete _athlete2 = await strava.updateLoggedInAthlete(80);
if (_athlete2.fault.statusCode != 200) {
print(
'Error in updateLoggedInAthlete ${_athlete2.fault.statusCode} ${_athlete2.fault.message}');
} else {
print('getRunningRaceById $_athlete2');
}
/// Gear should be owned by the loggedIn Athleted
/// Type of expected answer:
/// {"id":"b4366285","primary":true,"name":"Roubaix Specialized","resource_state":3,"distance":461692.0,
/// "brand_name":"Specialized","model_name":"Roubaix Expert","frame_type":3,"description":"So comfortable!"}
Gear _gear = await strava.getGearById("b4366285");
if (_gear.fault.statusCode != 200) {
print(
'error code getGearById ${_gear.fault.statusCode} ${_gear.fault.message}');
} else {
print('getGearById $_gear');
}
// IMPORTANT ------
// You have to join this club to do the test
final clubStravaMarseille = '226910';
/// Answer expected:
/// {"id":226910,"resource_state":3,"name":"STRAVA Marseille ",
/// "profile_medium":"https://dgalywyr863hv.cloudfront.net/pictures/clubs/226910/5003423/3/medium.jpg","profile":"https://dgalywyr863hv.cloudfront.net/pictures/clubs/226910/5003423/3/larg
Club _club = await strava.getClubById(clubStravaMarseille);
if (_club.fault.statusCode != 200) {
print(
'error code getClubById ${_club.fault.statusCode} ${_club.fault.message}');
} else {
print('getClubById $_club');
}
/// List the member of Strava club
/// Expected answer (should start like this):
/// [{"resource_state":2,"firstname":"Adam","lastname":"Š.","membership":"member",
/// "admin":false,"owner":false},{"resource_state":2,"firstname":"Alex","lastname":"M.","membership"
List<SummaryAthlete> _listMembers = await strava.getClubMembersById('1');
if (_listMembers[0].fault.statusCode != 200) {
print(
'error code getClubById ${_club.fault.statusCode} ${_club.fault.message}');
} else {
print('getClubMembersById ');
_listMembers.forEach((member) => print(
'${member.firstname} ${member.lastname} ${member.membership}'));
}
List<SummaryActivity> _listSumm =
await strava.getClubActivitiesById(clubStravaMarseille);
if (_listSumm[0].fault.statusCode != 200) {
print(
'error code getClubById ${_club.fault.statusCode} ${_club.fault.message}');
} else {
print('getClubActivitiesById ');
_listSumm.forEach((activity) =>
print('${activity.name} ${activity.totalElevationGain}'));
}
/// You have to put an id of one activity of the logged Athlete
/// You can find the id of one activity looking at your web page
/// https://www.strava.com/activities/2130215349
DetailedActivity _activity = await strava.getActivityById('2130215349');
if (_activity.fault.statusCode != 200) {
print('Error in getActivityById: ${_activity.fault.statusCode}');
} else {
print('getActivityById ${_activity.name}');
}
}
}
void deAuthorize() async {
// need to get authorized before (valid token)
final strava = Strava(
true, // to get disply info in API
secret, // Put your secret key in secret.dart file
);
var fault = await strava.deAuthorize();
}
@override
void dispose() {
strava.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(''),
Text('Authentication'),
Text('with other Apis'),
RaisedButton(
key: Key('OthersButton'),
child: Text('strava_flutter'),
onPressed: exampleStrava,
),
Text(''),
Text(' '),
Text(''),
Text(''),
Text('Push this button'),
Text(
'to revoke/DeAuthorize Strava user',
),
RaisedButton(
key: Key('DeAuthorizeButton'),
child: Text('DeAuthorize'),
onPressed: deAuthorize,
),
],
),
),
);
}
}
\ No newline at end of file
......@@ -340,6 +340,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
path_provider:
dependency: transitive
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
pedantic:
dependency: transitive
description:
......@@ -396,6 +403,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
shared_preferences:
dependency: transitive
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.3+4"
shelf:
dependency: transitive
description:
......@@ -443,6 +457,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
strava_flutter:
dependency: "direct main"
description:
name: strava_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.11+30"
stream_channel:
dependency: transitive
description:
......@@ -499,6 +520,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
url_launcher:
dependency: transitive
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.2"
vector_math:
dependency: transitive
description:
......@@ -536,4 +564,4 @@ packages:
version: "2.1.16"
sdks:
dart: ">=2.4.0 <3.0.0"
flutter: ">=1.2.1 <2.0.0"
flutter: ">=1.5.0 <2.0.0"
......@@ -13,7 +13,7 @@ dependencies:
cupertino_icons: ^0.1.2
jaguar_query_sqflite: ^2.2.10
scoped_model: ^1.0.1
strava_flutter: ^1.0.11+30
dev_dependencies:
flutter_test:
......@@ -21,7 +21,6 @@ dev_dependencies:
build_runner:
jaguar_orm_gen: 2.2.27
flutter:
uses-material-design: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment