.net FusiontablesService鉴权问题
本文关键字:问题 FusiontablesService net | 更新日期: 2023-09-27 18:18:29
我正试图在我的WPF应用程序中实现谷歌融合表api,以在我的谷歌地图中显示大量标记,但问题是,当我要验证函数"GetAuthorization"从不调用时。
public Fusion()
{
// Create the service.
objService = new FusiontablesService(new BaseClientService.Initializer()
{
Authenticator = CreateAuthenticator()
});
//GetAuthorization(provider);
}
/// <summary>
/// The remote service on which all the requests are executed.
/// </summary>
public FusiontablesService objService { get; private set; }
NativeApplicationClient provider = null;
private IAuthenticator CreateAuthenticator()
{
provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
{
ClientIdentifier = ClientCredentials.ClientID,
ClientSecret = ClientCredentials.ClientSecret
};
return new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
}
private IAuthorizationState GetAuthorization(NativeApplicationClient client)
{
// You should use a more secure way of storing the key here as
// .NET applications can be disassembled using a reflection tool.
const string STORAGE = "google.samples.dotnet.fusion";
const string KEY = "AIzaSyCtaH=6+";
string scope = FusiontablesService.Scopes.Fusiontables.GetStringValue();
// Check if there is a cached refresh token available.
IAuthorizationState state = AuthorizationMgr.GetCachedRefreshToken(STORAGE, KEY);
if (state != null)
{
try
{
client.RefreshToken(state);
return state; // Yes - we are done.
}
catch (DotNetOpenAuth.Messaging.ProtocolException ex)
{
CommandLine.WriteError("Using existing refresh token failed: " + ex.Message);
}
}
// Retrieve the authorization from the user.
state = AuthorizationMgr.RequestNativeAuthorization(client, scope);
AuthorizationMgr.SetCachedRefreshToken(STORAGE, KEY, state);
return state;
}
请帮我解决这个问题。
p。当我使用TaskService和BookService时,这个代码工作得很好。
Edit:忘记在IAuthenticator接口中没有暴露该方法
private IAuthenticator CreateAuthenticator()
{
provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
{
ClientIdentifier = ClientCredentials.ClientID,
ClientSecret = ClientCredentials.ClientSecret
};
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
auth.LoadAccessToken()
return auth;
}