Tuesday 15 March 2011

c# - Google Drive REST API Windows Forms login -



c# - Google Drive REST API Windows Forms login -

i'm having problem retrieving access token redirect uri. when seek coded procedure on mozilla redirected localhost access token, how instantiate webbrowser in c#? current code looks this:

public partial class form1 : form { public string client_id = "client_id"; public string client_secret= "client_secret"; public string redirect_uri = "http://localhost:5050"; public form1() { initializecomponent(); webbrowser.allownavigation = true; webbrowser.documentcompleted += webbrowser_documentcompleted; webbrowser.navigate(string.format("https://accounts.google.com/o/oauth2/auth?response_type=code&scope=email+profile&redirect_uri={0}&client_id={1}&hl=de&from_login=1&as=d832bdaf61552d&pli=1&authuser=0" ,redirect_uri, client_id)); } void webbrowser_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e) { webbrowser wb = sender webbrowser; //messagebox.show(wb.url.tostring()); if (wb.url.tostring().startswith("http://localhost")) { string[] s = wb.url.tostring().split('='); string authcode = s[s.length - 1]; messagebox.show("auth code: " + authcode); //webclient wc = new webclient(); //var info = new namevaluecollection(); //data["code"] = authcode; //data["client_id"] = client_id; //data["client_secret"] = client_secret; //data["redirect_uri"] = "http://localhost:5050"; //data["grant_type"] = "authorization_code"; //var response = wc.uploadvalues("accounts.google.com/o/oauth2/token", "post", data); //foreach (byte in response) //{ // messagebox.show(a.tostring()); //} } }

if know how googledrive api please share me.

please utilize uiwebbrowser instead of webbrowser , code should this.

public form1() { initializecomponent(); uiwebbrowser.allownavigation = true; uiwebbrowser.documentcompleted += webbrowser_documentcompleted; uiwebbrowser.navigate(string.format("https://accounts.google.com/o/oauth2/auth?response_type=code&scope=email+profile&redirect_uri={0}&client_id={1}&hl=de&from_login=1&as=d832bdaf61552d&pli=1&authuser=0" ,redirect_uri, client_id)); } void webbrowser_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e) { if (e.url.absoluteuri.startswith("http://localhost")) { // redirect end blank web browser command uiwebbrowser.navigate("about:blank"); code = e.url.query; } }

c# .net winforms rest google-drive-sdk

No comments:

Post a Comment