实例化HttpWebRequest并设置属性值: -
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://www.googleapis.com/upload/bigquery/v2/projects/776934660156/jobs");
request.Method = "POST";
request.ContentType = "multipart/related; boundary=xxx";
request.Headers.Add("Authorization: Bearer " + strAccessToken);//Service Account Access token
以下是HttpWebRequest对象的内容。当我通过此请求时,我收到错误400错误请求: -
--xxx
Content-Type: application/json; charset=UTF-8
{
"kind" : "bigquery#job" ,
"Id" : "testJob" ,
"configuration": {
"load": {
"destinationTable": {
"projectId": "776934660156",
"datasetId": "BMSTestDataset",
"tableId": "tblEvents"
},
"fieldDelimiter":"|",
}
}
}
--xxx
Content-Type: application/octet-stream
ET00000102|MT|50|Hindi|Halla Bol|2008-01-11 00:00:00|0|2007-08-07 15:51:38.240000000|<Genre><code>DRAMA</code></Genre>|<Legends><Actor>83</Actor><Actor>2457</Actor><Actor>1639</Actor><Actor>1151</Actor><Actor>1717</Actor><Actor>1526</Actor><Director>1801</Director><Music>820</Music></Legends>
ET00000103|MT|50|Hindi|Kisse Pyaar Karoon|2009-02-27 00:00:00|0|2007-08-07 17:16:36.443000000|<Genre><code>DRAMA</code></Genre>|<Legends><Actor>228</Actor><Actor>46</Actor><Actor>2539</Actor><Actor>2415</Actor><Actor>44</Actor><Actor>2161</Actor><Actor>2100</Actor><Director>82</Director><Music>2624</Music></Legends>
--xxx--
我没有指定架构,因为该表已存在于BQ数据集中。请帮帮我,我做了很多研究,但没有得到任何解决方案。
由于
答案 0 :(得分:1)
一些事情:
首先,BigQuery Load配置应如下所示(请注意Content-type标头后面的换行符:
--xxx
Content-Type: application/json; charset=UTF-8
{
'configuration': {
'load': {
// Schema, only if necessary
'schema': {
'fields': [
{'name':'f1', 'type':'STRING'},
{'name':'f2', 'type':'INTEGER'}
]
},
'destinationTable': {
'projectId': 'projectId',
'datasetId': 'datasetId',
'tableId': 'tableId'
}
}
}
}
--xxx
此外,如果要设置作业ID,请使用jobReference.jobId参数(请参阅BigQuery API load config documentation)。示例:
"jobReference": {
"jobId": 'SOMESTRINGHERE'
}
P.S。我认为使用随机边界字符串是一种好习惯,例如:
var boundary = "------------------------" + DateTime.Now.Ticks;