简体   繁体   中英

Gmail Api Authentication via Oauth Authentication In windows phone/ Asp.net

I am Trying to Get Google Authentication in Windows Phone, to Get Google Contact from gmail Account,

I try too much in Oauth Authentication, but its give me Exception i try to fix it, but could not find any Solution, here is my code,

 private async Task AuthenticateAsync()
    {
        if (service != null)
            return;

        try
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                //new Uri("/client_secrets.json"),
                   new Uri("ms-appx:///Assets/client_secrets.json"),
                    new[] { DriveService.Scope.DriveReadonly },
                    "user",
                    CancellationToken.None);
        }
        catch (Exception ex)
        {
           MessageDialog msgbox = new MessageDialog(ex.Message);
            msgbox.ShowAsync();
        }

        var initializer = new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "ASPSnippets",
        };

        service = new DriveService(initializer);
    }

here is Error i try to fix, but not understand how to fix it,

Message = "Google.Apis.Requests.RequestError\\r\\nLogin Required [401]\\r\\nErrors [\\r\\n\\tMessage[Login Required] Location[Authorization - header] Reason[required] Domain[global]\\r\\n]\\r\\n"

if any one have idea about it Then Help Me, Thanks In Advance.

Are you trying this through local system?

Please consider below points:-

1) Recheck the provided credentials for the authentication.

2) Try to host this code on a secure server (Https with Live IP), because sometimes the receiver sever only accept the request coming through the trusted server, This time of the problem I faced while implementing SAML 2.0, either you need to enable the server to accept the request from all the channels or have to send the secure request for the access.

3) This may be the Header section is not properly associated while sending the request.

I home some of the information might be help you.

Thanks Jitendra

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM