0

I am using oauth 1.0 and until now I can successfully get the Access Token from Google. But when I want to retrieve user contacts from https://www.google.com/m8/feeds/contacts/default/full, it return 401 error and no further explanation.

I find that the information form Google playground may not be really accurate, for example the signature base string in step 3 and step 5 include oauth_version but it is wrong. (If you include oauth_version, it will return signature_invalid and oauth_version is not included )

This is my request :

   HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sbGetContacts.ToString());
        req.Method = "GET";
        req.Headers.Add(authHeader);
        HttpWebResponse res = (HttpWebResponse)req.GetResponse();

This is my header:

        string authHeader = "Authorization: OAuth " +
        "oauth_version=" + "\"" + "1.0" + "\"" + "\"," +
        "oauth_nonce=" + "\"" + nonce + "\"," +
        "oauth_timestamp=" + "\"" + timeStamp + "\"," +
        "oauth_consumer_key=" + "\"" + GoogleconsumerKey + "\"," +
        "oauth_token=" + "\"" + OauthToken+ "\"," +
        "oauth_signature_method=" + "\"" + "HMAC-SHA1" + "\"," +
        "oauth_signature=" + "\"" + UpperCaseUrlEncode(sig) + "\"";

Can anyone tell me how to fix the problem ?

Android Developer
  • 987
  • 1
  • 8
  • 22

2 Answers2

0

OAuth1 is deprecated (by Google). Please don't spend any energy writing new code using OAuth1. With OAuth2 there are no signatures and crypto. Is there a reason you need to use OAuth1? We would like to know. I work on OAuth at Google.

nvnagr
  • 2,017
  • 1
  • 14
  • 11
0

Actually:

If your application has certain unusual authorization requirements, such as logging in at the same time as requesting data access (hybrid) or domain-wide delegation of authority (2LO), then you cannot currently use OAuth 2.0 tokens. In such cases, you must instead use OAuth 1.0 tokens and an API key. You can find your application's API key in the Google API Console, in the Simple API Access section of the API Access pane.

According to https://developers.google.com/google-apps/contacts/v3/?hl=fr

So you need to pass an API key. You can do this be adding key='YOUR_API_KEY' to the URL but how do you pass an API key if you are using a gdata client library?

Sérgio
  • 101
  • 3
  • 1
    i am hitting this url https://www.google.com/m8/feeds/contacts/default/full and also tried same url with email replacing default keyword ......but i am getting the frustated 401 error ..... – Vivek Pratap Singh May 25 '17 at 10:56