我在Big Query中創建了一個項目,並在API Access窗格中創建了服務帳戶,以便我可以通過代表用戶交互的Windows應用程序訪問Big Query API。由於我是使用和訪問Google API的新手,我想知道基本步驟,以便通過Windows服務訪問Big Query。通過Windows服務驗證BigQuery的步驟
1
A
回答
2
這裏有使用基於網絡的一些的OAuth .NET代碼示例流量: Google BigQuery with .NET documentation/ samples
爲了從在.NET中使用服務帳戶的另一dev的一個例子,請參閱本: Google OAuth2 Service Account Access Token Request gives 'Invalid Request' Response
這些手動實現在.NET庫頂部的服務帳戶。 .NET庫最近添加了對服務帳戶的本機支持,儘管我還沒有找到官方的例子。
這是一個非官方樣本,與Analytics API一起工作。它應該是直接類似於使用服務帳戶與BigQuery: How do I use a Service Account to Access the Google Analytics API V3 with .NET C#?
0
最後在這裏是身份驗證過程中大查詢API的工作代碼和檢索記錄,從大的查詢表: -
我已經創建了具有類返回類型OAuth2Authenticator<AssertionFlowClient>
的方法。
internal class clsGetOAuth2Authentication
{
public OAuth2Authenticator<AssertionFlowClient> objGetOAuth2(string strPrivateFilePath, string strPrivateFilePassword, string strServiceAccEmailId,string strScope)
{
AuthorizationServerDescription objAuthServerDesc;
X509Certificate2 objKey;
AssertionFlowClient objClient;
OAuth2Authenticator<AssertionFlowClient> objAuth = null;
string ScopeUrl = "https://www.googleapis.com/auth/" + strScope;
string strSrvAccEmailId = strServiceAccEmailId;
string strKeyFile = strPrivateFilePath; //KeyFile: This is the physical path to the key file you downloaded when you created your Service Account.
string strKeyPassword = (strPrivateFilePassword != "") ? strPrivateFilePassword : "notasecret"; //key_pass: This is probably the password for all key files, but if you're given a different one, use that.
objAuthServerDesc = GoogleAuthenticationServer.Description; //objAuthServerDesc: Description of the server that will grant Authentiation.
objKey = new X509Certificate2(strKeyFile, strKeyPassword, X509KeyStorageFlags.Exportable); //objkey: Load up and decrypt the key.
objClient = new AssertionFlowClient(objAuthServerDesc, objKey) { ServiceAccountId = strSrvAccEmailId, Scope = ScopeUrl }; //objClient: Using the AssertionFlowClient, because we're logging in with our certificate.
objAuth = new OAuth2Authenticator<AssertionFlowClient>(objClient, AssertionFlowClient.GetState); //objAuth: Requesting Authentication.
return objAuth;
}
}
現在,另一個類調用上述方法: -
clsGetOAuth2Authentication objOAuth2 = new clsGetOAuth2Authentication();
try
{
var objAuth = objOAuth2.objGetOAuth2(strKeyFile, strKeyPassword, strSrvAccEmailId, strScope); //Authentication data returned
objBQServ = new BigqueryService(objAuth); //Instantiate BigQueryService with credentials(objAuth) as its parameter
#region Retrieving Records:-
JobsResource j = objBQServ.Jobs;
QueryRequest qr = new QueryRequest();
qr.Query = strQuery;
DateTime dtmBegin = DateTime.UtcNow;
QueryResponse response = j.Query(qr, strProjId).Fetch();
DateTime dtmEnd = DateTime.UtcNow;
string strColHead = "";
foreach (var colHeaders in response.Schema.Fields)
{
strColHead += colHeaders.Name.ToString() + "\t";
}
Console.WriteLine(strColHead);
int intCount = 0;
foreach (TableRow row in response.Rows)
{
intCount += 1;
List<string> list = new List<string>();
foreach (var field in row.F)
{
list.Add(field.V);
}
Console.WriteLine(String.Join("\t", list));
}
TimeSpan tsElapsed = dtmEnd - dtmBegin;
Console.WriteLine("\n" + "Total no. of records:- " + intCount + ". Time taken:- " + tsElapsed);
#endregion
}
catch (Exception ex)
{
Console.WriteLine("Error Occured!" + "\n\n" + "Statement:- " + ex.Message.ToString() + "\n\n" + "Description:- " + ex.ToString() + "\n\n");
Console.WriteLine("\nPress enter to exit");
Console.ReadLine();
}
相關問題
- 1. Silverlight 4,RIA服務多步驟服務器端驗證
- 2. 跳過步驟x到步驟y並驗證步驟x數據
- 3. 在c#.net中驗證WebGet REST服務的步驟
- 4. 步驟嚮導驗證
- 5. Typo3後臺登錄身份驗證服務多個步驟
- 6. 在使用Google IMAP服務器時跳過驗證碼解析步驟
- 7. WCF通過Windows服務 - 身份驗證客戶端
- 8. WCF Rest服務通過瀏覽器進行Windows身份驗證
- 9. 如何通過curl驗證web服務?
- 10. Scrapy - 通過Google服務驗證
- 11. 通過URL驗證RTSP服務
- 12. 如何通過menuItemClick服務器驗證
- 13. 通過Windows服務在BigQuery表格中插入記錄
- 14. 如何通過PowerShell創建Windows服務ACS?服務器無法驗證請求
- 15. 通過報告服務連接到WCF Web服務,僅限Windows身份驗證?
- 16. 的Windows Phone 7 - 用於身份驗證的步驟推送通知
- 17. jQuery的步驟與引導驗證
- 18. JQuery MultiPage form ..每個步驟的驗證
- 19. 通過WSO2身份驗證服務器從LDAP獲取驗證
- 20. 多步驟JavaScript驗證,以防止進行到其他步驟
- 21. 步驟通過Netbeans中
- 22. Windows服務器證書的服務總線無法驗證
- 23. 使用AJAX PHP進行多步驟表單的服務器端驗證?
- 24. 調用函數Javascript/jQuery驗證之前的驗證步驟
- 25. Windows服務中的Kerberos身份驗證
- 26. Flexicapture 10 SDK驗證步驟問題
- 27. Knockout.js嚮導驗證每個步驟
- 28. mssql導出停止在驗證步驟
- 29. 如何驗證多個步驟FORM
- 30. JQuery表單步驟與驗證
非常感謝,我能夠生成有效的訪問令牌,但現在的問題是,如何通過這個訪問令牌到Big Query服務對象,以便我可以與Big Query API進行通信。我嘗試從我身邊以及我搜索大部分網站。 –