1
Я пытаюсь реализовать google fustion table api в своем приложении WPF, чтобы показать большое количество маркеров в моей карте google, но проблема в том, что когда я собираюсь аутентифицировать функцию GetAuthorization, никогда не звонят..net FusiontablesService authentication issue
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.S Этот код отлично работает, когда я использую TaskService и BookService.
я не нашел каких-либо функцию «objService.Authenticator.LoadAccessToken()». – Varun
Извините, забыли свою единственную часть класса OAuth2Authenticator. Обновите код. –