flutter - 使用 GmailApi 的正确方法是什么?
问题描述
我能够GmailApi
从googleapi
颤动中获得用户电子邮件的许可。但是我发现很难实现它。作为GmailApi
一个包,我确信我不必从正常情况下获取用户信息和邮件,http
所以我进行了一些研究,并遵循了一些教程和其他线程,googleapis
这与使用包导入的标签有关
import 'package:googleapis/gmail/v1.dart'
show
Label, Profile, GmailApi, Filter, Message, UsersResourceApi, Thread, BatchDeleteMessagesRequest, BatchDeleteMessagesRequest, Draft, UsersMessagesAttachmentsResourceApi;
//tags I mentioned in the paragraph above.
我能够获得用户邮件权限,并将 httpClient 初始化为登录用户。
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn googleSignIn = GoogleSignIn(
scopes: [
GmailApi.MailGoogleComScope,
GmailApi.GmailComposeScope,
GmailApi.MailGoogleComScope,
GmailApi.GmailInsertScope,
GmailApi.GmailLabelsScope,
GmailApi.GmailMetadataScope,
GmailApi.GmailModifyScope,
GmailApi.GmailReadonlyScope,
GmailApi.GmailSendScope,
GmailApi.GmailSettingsSharingScope,
]
);
final httpClient = googleSignIn.currentUser.authHeaders;
class GmailApi{
static const MailGoogleComScope = "https://mail.google.com/";
static const GmailComposeScope = "https://www.googleapis.com/auth/gmail.compose";
static const GmailInsertScope = "https://www.googleapis.com/auth/gmail.insert";
static const GmailLabelsScope = "https://www.googleapis.com/auth/gmail.labels";
static const GmailMetadataScope = "https://www.googleapis.com/auth/gmail.metadata";
static const GmailModifyScope = "https://www.googleapis.com/auth/gmail.modify";
static const GmailReadonlyScope = "https://www.googleapis.com/auth/gmail.readonly";
static const GmailSendScope = "https://www.googleapis.com/auth/gmail.send";
static const GmailSettingsBasicScope = "https://www.googleapis.com/auth/gmail.settings.basic";
static const GmailSettingsSharingScope = "https://www.googleapis.com/auth/gmail.settings.sharing";
final commons.ApiRequester _requester;
UsersResourceApi get users => new UsersResourceApi(_requester);
GmailApi(http.Client client,
{core.String rootUrl = "https://www.googleapis.com/",
core.String servicePath = "gmail/v1/users/"})
: _requester = new commons.ApiRequester(client, rootUrl, servicePath, USER_AGENT);
}
我找不到使用上述代码的方法,所以我尝试了这个,我认为这是正确的方法,但是没有步骤或文档可以遵循它,这与我在 和 上找到了一些线程和教程DriveApi
不同PeopleApi
。
这仅将值显示为空。我究竟做错了什么?
import 'package:googleapis/gmail/v1.dart';
class ListClass extends StatefulWidget {
@override
_ListClassState createState() => _ListClassState();
}
class _ListClassState extends State<ListClass> {
var leb = Profile();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(leb.emailAddress.toString()),
),
);
}
}
;
解决方案
推荐阅读
- swift - Swift:后台任务在 Apple Watch 模拟器中有效,但在设备中无效
- c++ - 如何使用 boost::karma/qi 解析日期时间?
- python - What is the best way to make a singly linked list of integer digits in Python?
- excel - 将多个工作簿中的单个工作表移动并保存为新文件
- gnupg - 有没有办法从 PGP 公钥中快速去除除一个 UID(用户 ID)之外的所有内容?
- c - 在 C 中创建具有 >1byte 键和值的哈希表
- unity3d - 如何为 Unity 映射我的搅拌机环境?
- r - 为什么在 R 中使用 tfestimators 包时出现此错误?
- javascript - className 元素上的事件侦听器,React Js
- python - 问:我如何为我的平台游戏制作收集币?