我正在尝试使用 Google+ API 访问经过身份验证的用户的信息。我已经从其中一个示例中复制了一些代码,这些代码可以正常工作(如下),但是我无法让它以一种我可以在应用程序启动时重用令牌的方式工作。
我尝试捕获“RefreshToken”属性并使用provider.RefreshToken()
(除其他外)并始终得到400 Bad Request
响应。
有谁知道如何进行这项工作,或者知道我在哪里可以找到一些样品?谷歌代码网站似乎没有涵盖这一点:-(
class Program
{
private const string Scope = "https://www.googleapis.com/auth/plus.me";
static void Main(string[] args)
{
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = "BLAH";
provider.ClientSecret = "BLAH";
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);
var plus = new PlusService(auth);
plus.Key = "BLAH";
var me = plus.People.Get("me").Fetch();
Console.WriteLine(me.DisplayName);
}
private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
{
// Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { Scope });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
// Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
// Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
}