abujehad139 / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

FusiontablesService authentication not working #335

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to implement google fustion table api in my WPF application to show 
large number of marker in my google map but problem is this when I am going to 
authenticate the function "GetAuthorization" never call.

    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;
    }

Please help me out of this issue.

P.S This code works fine when i am using TaskService and BookService.

Original issue reported on code.google.com by sh.va...@gmail.com on 14 Jun 2013 at 3:10

GoogleCodeExporter commented 9 years ago
I think that the right place to publish this question is in StackOverflow (with 
[google-fusion-tables] and [google-api-dotnet-client], when you will be able to 
get responses from this library developers, the fusion API owners and from 
other developers as well.

I'm closing this issue for now, please feel free to reopen if you think it 
should stay here. 

Original comment by pele...@google.com on 21 Jun 2013 at 1:38