所以我有这个代码 我的问题是,如果我已经通过OAuth验证了,我该如何配置 UserCredential ?
目前的情况是代码会显示另一个重定向到谷歌的登录页面。由于我已经使用asp.net MVC通过OAuth进行了身份验证,并且我已经拥有令牌如何摆脱 GoogleWebAuthorizationBroker 并直接传递令牌?
string[] scopes = new string[] {PlusService.Scope.PlusLogin,
PlusService.Scope.UserinfoEmail,
PlusService.Scope.UserinfoProfile};
UserCredential credential =
GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets
{
ClientId = "xxx.apps.googleusercontent.com",
ClientSecret = "xxxx"
},
scopes,
Environment.UserName,
CancellationToken.None,
new FileDataStore("Store")).Result;
PlusService service = new PlusService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "ArcaneChatV2",
});
PeopleResource.ListRequest listPeople = service.People.List("me", PeopleResource.ListRequest.CollectionEnum.Visible);
listPeople.MaxResults = 10;
PeopleFeed peopleFeed = listPeople.Execute();
var people = new List<Person>();
我不熟悉这种东西。
答案 0 :(得分:11)
假设您已拥有令牌,则可以执行以下操作
gl.glMultMatrixf(matrix);
然后,您可以将凭据传递给服务的初始化程序
答案 1 :(得分:1)
我们可以直接从访问令牌创建GoogleCredential
并使用它代替UserCredential
。我只是认为这可能对某人有所帮助。这是GmailService
初始化的代码段:
GoogleCredential cred = GoogleCredential.FromAccessToken(accessToken);
GmailService service = new GmailService(new BaseClientService.Initializer {HttpClientInitializer = cred});