ravipatidar54 / 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

Error while passing parameters to Contacts API #228

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use the url https://www.google.com/m8/feeds/contacts/EMAIL_ID/full to get 
the first set of results which works fine.
2. Try to retrieve the next set of contacts using the URL specified in the 
'next' parameter:
https://www.google.com/m8/feeds/contacts/EMAIL_ID/full?start-index=26&max-result
s=25
3. You will get 401 Unauthorized error

What is the expected output? What do you see instead?
401 Unauthorized error

What version of the product are you using? On what operating system?
Oauth v1.0. Windows 7. 64-bit

Please provide any additional information below.
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

Original issue reported on code.google.com by natraj1981 on 5 Jul 2012 at 11:49

GoogleCodeExporter commented 9 years ago
Hi,
It looks like you are not using this project at all, unfortunately this project 
does not offer support the the individual Api's. Try contacting the Contacts 
Api team or try a general community support site like stackoverflow.com.

Original comment by davidwat...@google.com on 28 Jul 2012 at 4:36