【发布时间】:2015-08-23 09:11:22
【问题描述】:
这是我的代码:
String key = Console.ReadLine(); //input oauth2.0 key from google
Console.WriteLine(key);
Google.Apis.Admin.Directory.directory_v1.DirectoryService service = new Google.Apis.Admin.Directory.directory_v1.DirectoryService(new BaseClientService.Initializer
{
ApplicationName = "MY APPLICATION",
ApiKey = key,
});
Google.Apis.Admin.Directory.directory_v1.UsersResource.GetRequest u = service.Users.Get("test@example.net");
Console.WriteLine(u.UserKey);
Google.Apis.Admin.Directory.directory_v1.Data.User response = await u.ExecuteAsync();
Console.WriteLine(response);
即使我有一个来自 Google 的 OAuth2.0 密钥“密钥”,我也会收到一条错误消息,回复内容类似于错误:需要登录。我应该如何更改代码,以便获取(并最终设置)用户信息而不会出现此类错误?
编辑:我的授权密钥范围是全局用户范围。
【问题讨论】:
-
您是否在请求标头中传递了 oauth 令牌?问题应该与 Authorization http 标头的值有关。检查此链接developers.google.com/api-client-library/dotnet/guide/aaa_oauth
标签: c# google-admin-sdk google-directory-api