c# - Authentication request returned unexpected result: 404 -
exception details: google.gdata.client.gdatarequestexception: execution of authentication request returned unexpected result: 404
here code:
protected void button1_click(object sender, eventargs e) { dataset ds = new dataset(); ds.tables.add("gmailcontacts"); ds.tables[0].columns.add("emailid"); requestsettings rs = new requestsettings("gmail", txtusername.value, txtpassword.value); rs.autopaging = true; contactsrequest cr = new contactsrequest(rs); feed<contact> feed = cr.getcontacts(); foreach (contact contact in feed.entries) { foreach (email email in contact.emails) { datarow dr = ds.tables[0].newrow(); dr["emailid"] = email.address.tostring(); ds.tables[0].rows.add(dr); } } gridview1.datasource = ds; gridview1.databind(); }
check own solution
steps:
- go https://console.developers.google.com/project , create project.
- select project, select apis & auth top left corner menu.
- select credentials
- create oauth button create new client id (application type - installed aplication.
- fill field product name
- save
after got client id native application with: client id, client secret, redirect uris
install google.apis.auth nuget
code
string clientid = null; // https://console.developers.google.com/project/xxx string clientsecret = null; // https://console.developers.google.com/project/xxx string accesscode = null; // code after getaccesstoken method string redirecturi = null; // https://console.developers.google.com/project/xxx string applicationname = null; // https://console.developers.google.com/project/xxx // scopes https://support.google.com/a/answer/162106?hl=en string scopes = null; // put scope https://www.google.com/m8/feeds/ string accesstype = "offline"; string tokentype = "refresh"; oauth2parameters parameters = new oauth2parameters { clientid = clientid, clientsecret = clientsecret, redirecturi = redirecturi, scope = scopes, accesstype = accesstype, tokentype = tokentype }; if (accesscode == null) { string url = oauthutil.createoauth2authorizationurl(parameters); // start webbrowser process.start(url); // load code web via popup, etc. parameters.accesscode = accesscodefromweb; } // check accesstoken , refreshtoken // after first acceess getaccesstoken information if (accesstoken == null || refreshtoken == null) { oauthutil.getaccesstoken(parameters); // save yours accesstoken , refreshtoken next connection accesstoken = parameters.accesstoken; refreshtoken = parameters.refreshtoken; } else { // restore token config file, etc. parameters.accesstoken = accesstoken; parameters.refreshtoken = refreshtoken; } requestsettings rs = new requestsettings(applicationname, parameters); return new contactsrequest(rs);
Comments
Post a Comment