【发布时间】:2016-07-18 07:52:18
【问题描述】:
我目前正在开发 Google Api,它旨在获取已登录人的圈子。我已经拥有 访问令牌,但问题是每当我尝试运行我的代码它返回这个异常
访问令牌已过期,但我们无法刷新它
我该如何解决这个问题?
var claimsforUser = await UserManager.GetClaimsAsync(User.Identity.GetUserId());
var access_token = claimsforUser.FirstOrDefault(x => x.Type == "urn:google:accesstoken").Value;
string[] scopes = new string[] {PlusService.Scope.PlusLogin,
PlusService.Scope.UserinfoEmail,
PlusService.Scope.UserinfoProfile};
var flow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = "xx-xx.apps.googleusercontent.com",
ClientSecret = "v-xx",
},
Scopes = scopes,
DataStore = new FileDataStore("Store"),
});
var token = new TokenResponse { AccessToken = access_token, ExpiresInSeconds=50000};
var credential = new UserCredential(flow, Environment.UserName, token);
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>();
while (peopleFeed.Items != null)
{
foreach (Person item in peopleFeed.Items)
{
people.Add(item);
}
if (peopleFeed.NextPageToken == null)
{
break;
}
listPeople.PageToken = peopleFeed.NextPageToken;
// Execute and process the next page request
peopleFeed = listPeople.Execute();
}
【问题讨论】:
标签: c# model-view-controller google-api google-api-dotnet-client