当我尝试使用服务帐户授权gmail api时,我收到以下错误
"客户端未经授权使用此方法检索访问令牌"
static async Task MainAsync()
{
sstageEntities db = new sstageEntities();
//UserCredential credential;
Dictionary<string, string> dictionary = new Dictionary<string, string>();
String serviceAccountEmail =
"xxx.iam.gserviceaccount.com";
var certificate = new X509Certificate2(
AppDomain.CurrentDomain.BaseDirectory +
"xxx-8c7a4169631a.p12",
"notasecret",
X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
//string userEmail = "user@domainhere.com.au";
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
User = "xxx@xxx.com",
Scopes = new[] { "https://mail.google.com/" }
}.FromCertificate(certificate)
);
// Create Gmail API service.
var gmailService = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
}); …Run Code Online (Sandbox Code Playgroud) 这是我的静态登录服务
login(email: string, password: string) {
debugger;
const user = {
username: email,
password: password,
};
if (email === "admin" && password === "admin") {
localStorage.setItem("currentUser", JSON.stringify(user));
}
if (localStorage.getItem("currentUser")) {
// logged in so return true
return user;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我的身份验证服务
export class AuthGuard implements CanActivate {
constructor(private router: Router) {
}
isAuthenticated(): boolean{
if (localStorage.getItem("currentUser")) {
return true;
}
else{
return false;
}
}
canActivate(): boolean {
if (!this.isAuthenticated()) {
this.router.navigate(['login']);
return false; …Run Code Online (Sandbox Code Playgroud) 我有一个在组件之间传递数据的服务,当它被调用时它可以工作,但是当我重新加载时,服务数据被重置。贮存 ?我很好奇的一件事是,我可以使用 rxjs 来实现这一点,但我不确定这会有什么帮助吗?我害怕使用 localstorage,因为数据将主要是对象或数组,而不是用户 ID 或会话 ID。对此的任何输入都会真的很有帮助。我制作了一个示例来帮助我。你可以在下面找到
我在 C# 中有两个列表对象,如下所述
List A
[0]
Count="0",
CountType="0",
InvTpeCode="DLX"
[1]
Count="0",
CountType="0"
InvTpeCode="STD"
List B
[0]
Count="2",
CountType="17"
[1]
Count="12",
CountType="14"
Run Code Online (Sandbox Code Playgroud)
我尝试使用 foreach 用列表 b 值更新列出 a 值,但不幸的是我无法带来所需的输出。
注意:两个列表的大小相同