c# - Google Contacts API - After getting the access token (oauth) -
c# - Google Contacts API - After getting the access token (oauth) -
i managed access token google's contacts api when seek create phone call retrieve logged in user's profile, 401 unauthorized error...
i did research , followed steps mentioned in "various" google documentations ( this one , this one , many others) no use...
so far think i'm signing request wrong. here's i'm doing after access token.
string outurl,querystring; string sig = oauth.generatesignature(new uri("https://www.google.com/m8/feeds/contacts/default/full"), server.urlencode(oauth.consumerkey), oauth.consumersecret, oauth.token, null, "get", timestamp, nonce, out outurl, out querystring); string requrl = "https://www.google.com/m8/feeds/contacts/default/full?access_token=" + oauth.token + "&oauth_signature_method=hmac-sha1&oauth_signature=" + server.urlencode(sig) + "&oauth_consumer_key=" + oauth.consumerkey + "&oauth_timestamp=" + timestamp + "&oauth_nonce=" + nonce + "&oauth_version=1.0"; response = oauth.webrequest(oauthgoogle.method.get, requrl, string.empty);
the 401 error appears when send request using oauth.webrequest() (the lastly line of code above)
i need rid of 401 error...i'm using asp.net/c#. help appreciated. give thanks you...
your code illustration defines requrl
not used , uses url
not defined.
you provide oauth request parameters authorization header rather querystring.
http://oauth.net/core/1.0/#auth_header_authorization
i imagine signing request , setting authorization that's beingness handled within oauth object.
to clarify
i have used method sign http requests in oauth 1.0a implementation:
/// <summary> /// gets authorization header. /// </summary> /// <param name="method">the method.</param> /// <param name="url">the url of request.</param> /// <param name="parameters">the parameters.</param> /// <returns>authorization header</returns> public string getauthorizationheader(string method, uri url, namevaluecollection parameters) { parameters.set("oauth_consumer_key", this.consumerkey); parameters.set("oauth_nonce", this.getnonce()); parameters.set("oauth_timestamp", this.gettimestamp()); parameters.set("oauth_version", "1.0"); parameters.set("oauth_signature_method", "hmac-sha1"); string signstring = this.getsignstring(method, url, parameters); string signature = this.getsignature(signstring, this.consumersecret, this.tokensecret); parameters.set("oauth_signature", signature); stringbuilder authorizationheader = new stringbuilder(); foreach (string paramkey in parameters.allkeys) { if (authorizationheader.length > 0) { authorizationheader.append(", "); } else { authorizationheader.append("oauth "); } authorizationheader.appendformat("{0}=\"{1}\"", paramkey, oauthhelper.urlencode(parameters[paramkey])); } homecoming authorizationheader.tostring(); }
which utilize this
public void signhttpwebrequest(string token, string tokensecret, ref httpwebrequest request) { namevaluecollection parameters = new namevaluecollection(); this.tokensecret = tokensecret; parameters.set("oauth_token", token); request.headers.add("authorization", this.getauthorizationheader(request, parameters)); }
c# asp.net api oauth
Comments
Post a Comment