500 px api with C# throwing 500 Internal Server Error -
500 px api with C# throwing 500 Internal Server Error -
trying implement 500px api c#. able authenticate user 500px api unable access_token in exchange of response_token leaves 3rd step of oauth 1.0 incomplete. able authorize user , oauth_token , oauth_verifier when utilize oauth_token making next request :-
https://api.500px.com/v1/oauth/access_token
500 internal server error along next screen gets thrown
i have debugged code one thousand times, tried different ways form url, added various parameters request no help. badly stuck no info available on 500px developer website or on web using api in c#. have reached dead-end! next code:-
1.]for requesting token , authorizing user :-
string normalizedurl; string normalizedrequestparameters; oauth.oauthbase myoauth = new oauth.oauthbase(); seek { uri uri = new uri("https://api.500px.com/v1/oauth/request_token"); string consumerkey = "u26x4av9ydnpd7ktet7bunfcdjhqvttywidoc1la"; string consumersecret = "73iafpqcr4xkh3dgyicpautqhi6tmhwchdivnop7"; string timestamp = myoauth.generatetimestamp(); string nonce = myoauth.generatenonce(); myoauth.includeversion = true; string signature = myoauth.generatesignature(uri, consumerkey, consumersecret, "", "", "get", timestamp, nonce, oauth.oauthbase.signaturetypes.hmacsha1, out normalizedurl, out normalizedrequestparameters); string authorizationurl = normalizedurl + "?" + normalizedrequestparameters + "&oauth_signature=" + myoauth.urlencode(signature); uri signinurl = new uri(authorizationurl); httpwebrequest request = (httpwebrequest)webrequest.create(signinurl); httpwebresponse response = (httpwebresponse)request.getresponse(); streamreader stin = new streamreader(response.getresponsestream()); string responsestring = stin.readtoend(); stin.close(); //oauth_token=cf40227bb7ede4d6e56ff790324761b3&oauth_token_secret=0bcb59dff2c1d095739c86c534fc62d7ed224fecfe8744d48c9c95f36211382f if (responsestring.contains("oauth_token=") && responsestring.contains("oauth_token_secret=")) { string resptoken = responsestring.split('&')[0].replace("oauth_token=", ""); string respsecret = responsestring.split('&')[1].replace("oauth_token_secret=", ""); uri = new uri("https://api.500px.com/v1/oauth/authorize"); timestamp = myoauth.generatetimestamp(); nonce = myoauth.generatenonce(); myoauth.includeversion = true; signature = myoauth.generatesignature(uri, consumerkey, consumersecret, resptoken , respsecret, "get", timestamp, nonce, oauth.oauthbase.signaturetypes.hmacsha1, out normalizedurl, out normalizedrequestparameters); console.writeline("signature=="+signature); authorizationurl = normalizedurl + "?" + normalizedrequestparameters + "&oauth_signature=" + myoauth.urlencode(signature); uri signinurl1 = new uri(authorizationurl); webbrowser1.navigate(signinurl1);
}
2.]after user clicks on authorise application getting access_token:-
private void webbrowser_navigated(object sender, webbrowsernavigatedeventargs e) { string parameters; string normalizedurl; string normalizedrequestparameters; string consumerkey = "u26x4av9ydnpd7ktet7bunfcdjhqvttywidoc1la"; string consumersecret = "73iafpqcr4xkh3dgyicpautqhi6tmhwchdivnop7"; oauth.oauthbase myoauth = new oauth.oauthbase(); seek { if (e.url.tostring().contains("https://www.xyz.com/")) { string url = (e.url.tostring()).replace("https://www.xyz.com/?",""); if( url.contains("oauth_token=")) { string oauthtoken = url.split('&')[0].replace("oauth_token=", ""); var uri = "https://api.500px.com/v1/oauth/access_token"; oauthbase oauth = new oauthbase(); var nonce = oauth.generatenonce(); var timestamp = oauth.generatetimestamp(); var signature = oauth.generatesignature(new uri(uri), consumerkey, consumersecret, oauthtoken, string.empty, "post", timestamp, nonce, oauthbase.signaturetypes.hmacsha1, out normalizedurl, out normalizedrequestparameters); signature = httputility.urlencode(signature); var requesturi = normalizedurl + "?" + "oauth_callback=https://www.xyz.com" +"?"+ normalizedrequestparameters + "&oauth_signature=" + myoauth.urlencode(signature); console.writeline(requesturi); var request = (httpwebrequest)webrequest.create(requesturi.tostring()); request.method = webrequestmethods.http.post; request.contenttype = "application/json"; // request.contenttype = "application / x - www - form - urlencoded"; //request.credentials = credentialcache.defaultcredentials; //request.useragent = "mozilla/4.0 (compatible; msie 7.0; windows nt 6.0)"; var response = request.getresponse(); var reader = new streamreader(response.getresponsestream()); var accesstoken = reader.readtoend(); } } catch(exception ex) { console.writeln(ex.tostring()); } }
now next line code breaking:-
var response = request.getresponse();
completely @ wits end on issue, not able root of it. help directions highly appreciated. suggestions of great help!! thanks ton in advance!
here's do:
use rather post (post may work; i've not tried , have had little success 500px , posting)
include oauth_verifier received during authorisation step in query url
sign entire query using consumer key , request token secret (returned in step 1)
code snippet should homecoming "oauth_token=...&oauth_token_secret=..." in http reply body.
make sure oauth implementation doesn't strip out parameters origin "oauth_"! mine , stripping out oauth_verifier parameter required 500px.
oauth.oauthbase oauth = new oauth.oauthbase(); string strurl = ""; string strparams = ""; string signature = oauth.generatesignature(new uri(api_url + "oauth/access_token?oauth_verifier=" + this.oauthverifier), this.consumerkey, this.consumersecret, this.oauthtoken, this.requesttokensecret, "get", oauth.generatetimestamp(), oauth.generatenonce(), oauth.oauthbase.signaturetypes.hmacsha1, out strurl, out strparams); string authorizationurl = strurl + "?" + strparams + "&oauth_signature=" + system.web.httputility.urlencode(signature); debug.writeline("url>" + authorizationurl); response reply = sendgetrequest(authorizationurl); if (reply.success) { debug.writeline("access_token>" + reply.content);
c# api oauth
Comments
Post a Comment