.net - 终端中的 GoogleWebAuthorizationBroker.AuthorizeAsync
问题描述
我正在使用常见的方法:
GoogleWebAuthorizationBroker.AuthorizeAsync
授权我对 Admob API 进行的一些调用。
在我的机器上,一切正常,因为我在 macos 上,当我需要输入身份验证信息时,浏览器会打开。
但是,我怎样才能在终端中做到这一点?目标服务器将有一个 ubuntu 终端并且没有安装 X。我应该为此使用 oauth2l 吗?
这是我用来进行初始登录的基本代码:
var secrets = GoogleClientSecrets.Load(stream).Secrets;
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
secrets,
new[] {AdMobService.Scope.AdmobReport},
"user",
CancellationToken.None,
new FileDataStore("Store"));
string temp = await credential.GetAccessTokenForRequestAsync();
var service = new AdMobService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyApp",
});
var accounts = await service.Accounts.List().ExecuteAsync();
这是我将使用(尚未测试)来刷新令牌的代码:
TokenResponse token = new TokenResponse
{
RefreshToken = "XXXXX",
};
var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = secrets,
Scopes = new[] {AdMobService.Scope.AdmobReport},
DataStore = new FileDataStore("Store")
});
var credential = new UserCredential(flow, "user", token);
解决方案
推荐阅读
- javascript - ReactJS 客户端和 ExpressJS 后端应用制作问题
- javascript - Google Drive API:如何在 appDataFolder 中创建文件?
- grafana - Grafana - 如何“组合”两个不同的仪表板(JSON)?
- python - 如何在 Django 中使用 create 插入数据
- r - 如何指定自定义格式化程序函数 gt table grand summary?
- ubuntu - 是否不再可以独立于 Scratch 在 Ubuntu 衍生产品中为 Squeak 进行存储库安装?
- javascript - 获取字符串数组javascript的总和
- java - 如何将字符串从一个索引交换到另一个索引?
- xamarin - 更改 CollectionView 中所选项目的背景颜色不适用于 UWP
- php - 在两个目录中查找文件名匹配并将匹配的文件名写入数组