Having problems using Google sheet as a source in SSIS -
i able import data google sheet sql server @ 1 point using method detailed in article. google deprecated clientlogin broke method , have been trying functionality , running.
i turned using oauth service account try , authenticate google described here cannot work within integration services project.
in project create data flow task script component source. use following code in script:
using system; using system.data; using microsoft.sqlserver.dts.pipeline.wrapper; using microsoft.sqlserver.dts.runtime.wrapper; using google.apis.auth.oauth2; using google.gdata.client; using google.gdata.spreadsheets; using system.security.cryptography.x509certificates; using google.gdata.extensions; [microsoft.sqlserver.dts.pipeline.ssisscriptcomponententrypointattribute] public class scriptmain : usercomponent { public class scriptmain : usercomponent { listfeed objlistfeed; public override void preexecute() { base.preexecute(); string keyfilepath = @"c:\key.p12"; // found in developer console string serviceaccountemail = "myaccount@developer.gserviceaccount.com"; // found in developer console var certificate = new x509certificate2(keyfilepath, "notasecret", x509keystorageflags.exportable); serviceaccountcredential credential = new serviceaccountcredential(new serviceaccountcredential.initializer(serviceaccountemail) //create credential using certigicate { scopes = new[] { "https://spreadsheets.google.com/feeds/" } //this scopr spreadsheets, check google scope faq others }.fromcertificate(certificate)); credential.requestaccesstokenasync(system.threading.cancellationtoken.none).wait(); //request token var requestfactory = new gdatarequestfactory("my app user agent"); requestfactory.customheaders.add(string.format("authorization: bearer {0}", credential.token.accesstoken)); spreadsheetsservice myservice = new spreadsheetsservice("my-service"); //create old service myservice.requestfactory = requestfactory; //add new request factory old service spreadsheetquery query = new spreadsheetquery(); //do job done before spreadsheetfeed feed = myservice.query(query); worksheetquery objworksheetquery = new worksheetquery("sheet-id", "private", "full"); worksheetfeed objworksheetfeed = myservice.query(objworksheetquery); worksheetentry objworksheet = (worksheetentry)objworksheetfeed.entries[0]; atomlink objlistfeedlink = objworksheet.links.findservice(gdataspreadsheetsnametable.listrel, null); listquery objlistquery = new listquery(objlistfeedlink.href.tostring()); objlistfeed = myservice.query(objlistquery); } /// <summary> /// method called after rows have passed through component. /// /// can delete method if don't need here. /// </summary> public override void postexecute() { base.postexecute(); /* * add code here */ } public override void createnewoutputrows() { foreach (listentry objrow in objlistfeed.entries) { output0buffer.addrow(); output0buffer.responseid = objrow.elements[0].value; output0buffer.deptid = convert.toint16(objrow.elements[1].value); output0buffer.timestamp = convert.todatetime(objrow.elements[3].value); output0buffer.username = objrow.elements[4].value; output0buffer.department = objrow.elements[2].value; output0buffer.extractdate = datetime.now; } output0buffer.endofrowset(); } }
i build script , no errors when try , run package following runtime error:
could not load file or assembly 'google.apis.auth.platformservices, version=1.9.3.19383, culture=neutral, publickeytoken=4b01fa6e34db77ab' or 1 of dependencies. system cannot find file specified.
i added reference google.apis.auth.platformservices in script project i'm not sure doing wrong. i've created console application project similar code use nuget reference google apis auth client library , code runs fine. have tried doing same thing in script project following error when trying build script:
this project references nuget package(s) missing on computer. enable nuget package restore download them.
anyone know i'm doing wrong or how make work?
i able working adding dll's in nuget package gac , referencing there. faced version dependency error overcame adding binding redirect in machine.config. not elegant solution needed make work , other methods tried weren't meeting success.
Comments
Post a Comment