错误:此方法需要'fields'参数

时间:2019-01-10 16:21:15

标签: c# google-drive-api

<Viewbox 
        Stretch="Uniform" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch">
    <Canvas Width="200" Height="200">
        <Ellipse
            Canvas.Left="0"
            Canvas.Top="0"
            Width="200"
            Height="200"
            Fill="Yellow"
            Stroke="Black" />
        <Path x:Name="Bridge"
              Width="34.5"
              Height="69.5"
              Canvas.Left="65.5"
              Canvas.Top="63"
              HorizontalAlignment="Left"
              VerticalAlignment="Top"
              Data="M149,127 L115.5,195.5"
              Fill=" Yellow"
              Stretch="Fill"
              Stroke="Black" />
        <Path x:Name="Nose"
              Width="38.5"
              Height="1.008"
              Canvas.Left="65.5"
              Canvas.Top="145.5"
              HorizontalAlignment="Left"
              VerticalAlignment="Top"
              Data="M115.5,196.492 L153,196.5"
              Fill=" Yellow"
              Stretch="Fill"
              Stroke="Black" />
        <Rectangle x:Name="SquareEye"
                   Width="24"
                   Height="24"
                   Canvas.Left="53.984"
                   Canvas.Top="68"
                   HorizontalAlignment="Left"
                   VerticalAlignment="Top"
                   Fill="Yellow"
                   Stroke="Black" />
        <Ellipse x:Name="CircleEye"
                 Width="24"
                 Height="24"
                 Canvas.Left="119"
                 Canvas.Top="68"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Top"
                 Fill="Yellow"
                 Stroke="Black" />
    </Canvas>
</Viewbox>

我正在尝试使用Google Drive API(.v3)中的“关于”资源,并收到我似乎无法解决的错误,该错误在文档中未得到解决。我花了几天时间研究无济于事,并且不太了解错误消息告诉我的内容。使用API​​的新手。 :)

P。 S. oRequest.Fields不存在。也尝试过。

Google API: Google.Apis.Requests.RequestError
The 'fields' parameter is required for this method. [400]
Errors[
Message[The 'fields' parameter is required for this method.] Location[fields - parameter] Reason[required] Domain[global]
]

已更新:以下代码是一种改进,但在结果行上生成“对象引用未设置为对象的实例” ...:\

string result = "success";
try {
    About oRequest = driveService.About.Get().Execute();
    result = result + oRequest.User;
} catch (Exception e) {
    result = "Google API: " + e.Message;
}
textBox1.Text = result;
return result;

2 个答案:

答案 0 :(得分:0)

工作代码:

string result = "success";
try {
    AboutResource.GetRequest oRequest = driveService.About.Get();
    oRequest.Fields = "*";
    About oResponse = oRequest.Execute();
    result = JsonConvert.SerializeObject(oResponse);
} catch (Exception e) {
    result = "Google API: " + e.InnerException;
}
textBox1.Text = result;
return result;

答案 1 :(得分:0)

如果您将“用户”用作字段,则还可以请求完整的用户对象Google.Apis.Drive.v3.Data.User

例如:

var request = service.About.Get();
request.Fields = "user";
var user = request.Execute().User;

不是获得完整的响应对象Google.Apis.Drive.v3.Data.About