api kicking my ass :( I tried 3 different attempts for authorization but no luck

This commit is contained in:
kwainright
2020-05-03 14:54:57 -04:00
parent 68c7b5c5b3
commit f819278368
3 changed files with 25 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import 'package:capstone_hungry_hippos/screens/twitter_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:twitter_api/twitter_api.dart'; import 'package:twitter_api/twitter_api.dart';
import'package:crypto/crypto.dart';
import 'dart:convert'; import 'dart:convert';
@@ -15,7 +16,7 @@ final twitterBase = 'https://api.twitter.com/1.1/search';
final _twitterOauth = new twitterApi( final _twitterOauth = new twitterApi(
consumerKey: "gsa3eHPVGK90dt6fgUC2ZSbTE", consumerKey: "gsa3eHPVGK90dt6fgUC2ZSbTE",
consumerSecret: "rwEjykGOfapPLTVkWgedSCU8Eld130EEHFyu3W0Ye3fDcKj5Vf", consumerSecret: "rwEjykGOfapPLTVkWgedSCU8Eld130EEHFyu3W0Ye3fDcKj5V",
token: "910563313108574211-WynoAeUKJrnE6uXPv8vJGx4ITGS1ggG", token: "910563313108574211-WynoAeUKJrnE6uXPv8vJGx4ITGS1ggG",
tokenSecret: "dWFYYbn6J1QTyV86femOdriX7MfMSANSjH3m48ZtEZUNW", tokenSecret: "dWFYYbn6J1QTyV86femOdriX7MfMSANSjH3m48ZtEZUNW",
); );
@@ -27,6 +28,7 @@ class TwitterFeedCreation {
Future<List<Tweet>> getPage() async { Future<List<Tweet>> getPage() async {
var response = await _twitterOauth.getTwitterRequest( var response = await _twitterOauth.getTwitterRequest(
"GET", "GET",
"/statuses/user_timeline.json", "/statuses/user_timeline.json",
@@ -41,9 +43,29 @@ class TwitterFeedCreation {
Iterable tweets = json.decode(response.body); Iterable tweets = json.decode(response.body);
print(tweets); print(tweets);
return tweets.map((e) => Tweet.fromJson(e)).toList(); return tweets.map((e) => Tweet.fromJson(e)).toList();
} }
} }
String _getSig(String method, String base, List<String> sortedItems){
String param = '';
for (int i = 0; i < sortedItems.length; i++) {
if (i == 0) {
param = sortedItems[i];
} else {
param += '%${sortedItems[i]}';
}
}
String sig = '$method&${Uri.encodeComponent(base)}&${Uri.encodeComponent(param)}';
String key = '${Uri.encodeComponent("gsa3eHPVGK90dt6fgUC2ZSbTE")}&${Uri.encodeComponent("rwEjykGOfapPLTVkWgedSCU8Eld130EEHFyu3W0Ye3fDcKj5V")}';
var digest = Hmac(sha1, utf8.encode(key)).convert(utf8.encode(sig));
return base64.encode(digest.bytes);
}
class VerticalTwitterFeed extends StatelessWidget{ class VerticalTwitterFeed extends StatelessWidget{

View File

@@ -58,7 +58,7 @@ packages:
source: hosted source: hosted
version: "2.1.1" version: "2.1.1"
crypto: crypto:
dependency: transitive dependency: "direct main"
description: description:
name: crypto name: crypto
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

View File

@@ -25,6 +25,7 @@ dependencies:
http: ^0.12.0+4 http: ^0.12.0+4
shared_preferences: ^0.5.6+3 shared_preferences: ^0.5.6+3
twitter_api: ^0.1.2 twitter_api: ^0.1.2
crypto:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.