a-marenkov / gsheets

A Dart library for working with Google Sheets API.
Other
79 stars 31 forks source link

Unhandled Exception: SocketException: Connection failed #45

Closed hetkpatel closed 3 years ago

hetkpatel commented 3 years ago

I'm thinking this is an issue with credentials but would like to get another pair of eyes on this issue.

Error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: SocketException: Connection failed (OS Error: Operation not permitted, errno = 1), address = accounts.google.com, port = 443

Flutter Code:

import 'package:flutter/material.dart';
import 'package:gsheets/gsheets.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  void initState() {
    super.initState();
    _setupGSheet();
  }

  void _setupGSheet() async {
    const _credentials = r'''
    {
      "type": "service_account",
      "project_id": "",
      "private_key_id": "",
      "private_key": "",
      "client_email": "",
      "client_id": "",
      "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",
      "client_x509_cert_url": ""
    }
    ''';
    const _spreadsheetId = 'SPREADSHEET_ID';

    // init GSheets
    final gsheets = GSheets(_credentials);
    // fetch spreadsheet by its id
    final ss = await gsheets.spreadsheet(_spreadsheetId);
    // get worksheet by its title
    final sheet = ss.worksheetByTitle('Sheet1');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Hello, World'),
      ),
      body: Center(
        child: Text('loading gsheet'),
      ),
    );
  }
}
hetkpatel commented 3 years ago

https://github.com/flutter/flutter/issues/47606