Hi,

I am getting 401 Unauthorized error while passing parameters to the 
Contacts API for fetching my contacts. However, I am able to retrieve 
results when I don't pass any parameters. 

I am using the url https://www.google.com/m.../contacts/EMAIL_ID/full 
<https://www.google.com/m8/feeds/contacts/EMAIL_ID/full>to get the first 
set of results which works fine.
The error is happening when I try to retrieve the next set of contacts 
using the URL specified in the 'next' parameter:
https://www.google.com/m...x=26&max-results=25 
<https://www.google.com/m8/feeds/contacts/EMAIL_ID/full?start-index=26&max-results=25>

Below is the code I am using for the API call:

public string GetUserContacts(string url)
{
string contactsXml = string.Empty; 


string timestamp = GenerateTimeStamp();
string nonce = GenerateNonce();

// Build signature base.
StringBuilder sig = new StringBuilder();
sig.Append("oauth_consumer_key=" + UrlEncode(consumerKey));
sig.Append("&oauth_nonce=" + UrlEncode(nonce));
sig.Append("&oauth_signature_method=" + UrlEncode("HMAC-SHA1"));
sig.Append("&oauth_timestamp=" + UrlEncode(timestamp));
sig.Append("&oauth_token=" + UrlEncode(accessToken));
sig.Append("&oauth_version=" + UrlEncode("1.0"));

string signatureBase = "GET" + "&" + UrlEncode(url) + "&" + 
UrlEncode(sig.ToString());


// Calculate signature.
string signature = ComputeHmacSha1Signature(signatureBase, consumerSecret, 
accessTokenSecret);

//Build Authorization header.
StringBuilder authHeader = new StringBuilder();
authHeader.Append("Authorization: OAuth ");
authHeader.Append("oauth_version=\"1.0\", ");
authHeader.Append("oauth_nonce=\"" + nonce + "\", ");
authHeader.Append("oauth_timestamp=\"" + timestamp + "\", ");
authHeader.Append("oauth_consumer_key=\"" + consumerKey + "\", ");
authHeader.Append("oauth_token=\"" + UrlEncode(accessToken) + "\", ");
authHeader.Append("oauth_signature_method=\"HMAC-SHA1\", ");
authHeader.Append("oauth_signature=\"" + UrlEncode(signature) + "\", ");


// Create web request and read response.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Headers.Add(authHeader.ToString());
using (WebResponse response = request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
contactsXml = reader.ReadToEnd(); 
}
}

return contactsXml;
}

Any idea why this is happening? 

Any help would be much appreciated.

Thanks,
Nataraj

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html

Reply via email to