The remote server returned an error: (401) Unauthorized.

1,208 views
Skip to first unread message

katta nagaraj kumar

unread,
Mar 28, 2012, 7:22:36 AM3/28/12
to google-docum...@googlegroups.com
I am trying to get the list of documents available but failed with an exception "The remote server returned an error: (401) Unauthorized."

Any help would be much appreciated!

Below is the code snippet
--------------------------------------
        static void Main(string[] args)
        {
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("cl", "DocumentServiceSample");
            authFactory.AccountType = "HOSTED";
            Service service = new DocumentsService("DocumentServiceSample");

            service.RequestFactory = authFactory;
            service.setUserCredentials(@"xxxx...@gmail.com", @"xxxxxxxx");
            string str1 = service.QueryClientLoginToken();


            DocumentsListQuery query = new DocumentsListQuery();
            AtomFeed feed = service.Query(query);
            string str = feed.Entries[0].XmlName;
            foreach (DocumentEntry entry in feed.Entries)
            {

                Console.WriteLine("FileName:{0}", entry.Title.Text);

            }
        }

regards,
nagaraj

Claudio Cherubino

unread,
Mar 28, 2012, 12:12:51 PM3/28/12
to google-docum...@googlegroups.com
Hi Nagaraj,

Your code mixes ClientLogin with the OAuth flow.
If you want to authenticate using username and password (ClientLogin) and retrieve all documents, it should look like the following:


        static void Main(string[] args)
        {
            DocumentsService service = new DocumentsService("DocumentServiceSample");
            service.setUserCredentials(@"xxxx...@gmail.com", @"xxxxxxxx");

            DocumentsListQuery query = new DocumentsListQuery();
            AtomFeed feed = service.Query(query);

katta nagaraj kumar

unread,
Mar 29, 2012, 3:34:50 AM3/29/12
to google-docum...@googlegroups.com
HI Claudio,

Thanks Claudio, your sample worked using ClientLogin, but i was looking for OAuth?
how can we make it work the same sample with OAuth?

Regards,
Nagaraj

Claudio Cherubino

unread,
Mar 29, 2012, 12:03:56 PM3/29/12
to google-docum...@googlegroups.com
Hi Nagaraj,

Please check the examples at 


Claudio
Reply all
Reply to author
Forward
0 new messages